Using the govc container in Jenkins

I’d like to run govc commands in a Jenkins pipeline. Running the govc container manually works:

docker pull vmware/govc && docker run -e GOVC_USERNAME=$GOVC_USERNAME -e GOVC_PASSWORD=$GOVC_PASSWORD -e GOVC_INSECURE=$GOVC_INSECURE vmware/govc find -u=$GOVC_URL / -type m

For some reason the short environment variable passing version (-e ENV_VAR) doesn’t work with this image and I must enter GOVC_URL as a govc argument, but besides these the command returns the right output.

This is the pipeline I wrote for the command:

pipeline {
    agent {
        docker { image 'vmware/govc' }
    }
    stages {
        stage('test govc') {
            steps {
                script {
                    def govcEnvVars = [
                        GOVC_INSECURE: 1,
                        GOVC_USERNAME: 'my_user',
                        GOVC_PASSWORD: 'my_password,
                        GOVC_URL: 'my_url'
                    ]
                    withEnv(govcEnvVars.collect { k, v -> "${k}=${v}" }) {
                        sh 'govc find -u="$GOVC_URL" / -type m'
                    }
                }
            }
        }
    }
}

Now, no matter what command I try to run I always get the following error message in the console log:

ERROR: The container started but didn't run the expected command. Please double check your ENTRYPOINT does execute the command passed as docker run argument, as required by official docker images (see https://github.com/docker-library/official-images#consistency for entrypoint consistency requirements).
Alternatively you can force image entrypoint to be disabled by adding option `--entrypoint=''`.

What am I doing wrong?

Source: StackOverflow

LEAVE A COMMENT