Jenkins Kubernetes Plugin doesn't executre entrypoint of Docker image

7/11/2019

I'm fairly new into Jenkins Kubernetes Plugin and Kubernetes in general - https://github.com/jenkinsci/kubernetes-plugin

I want to use the plugin for E2E tests setup inside my CI.

Inside my Jenkinsfile I have a podTemplate which looks and used as follows:

def podTemplate = """
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: website
    image: ${WEBSITE_INTEGRATION_IMAGE_PATH}
    command:
      - cat
    tty: true
    ports:
     - containerPort: 3000
  - name: cypress
    resources:
      requests:
        memory: 2Gi
      limit:
        memory: 4Gi
    image: ${CYPRESS_IMAGE_PATH}
    command:
      - cat
    tty: true
"""

pipeline {
  agent {
    label 'docker'
  }
  stages {
    stage('Prepare') {
      steps {
        timeout(time: 15) {
          script {
            ci_machine = docker.build("${WEBSITE_IMAGE_PATH}")
          }
        }
      }
    }

    stage('Build') {
      steps {
        timeout(time: 15) {
          script {
            ci_machine.inside("-u root") {
              sh "yarn build"
            }
          }
        }
      }

      post {
        success {
          timeout(time: 15) {
            script {
              docker.withRegistry("https://${REGISTRY}", REGISTRY_CREDENTIALS) {
                integrationImage = docker.build("${WEBSITE_INTEGRATION_IMAGE_PATH}")
                integrationImage.push()
              }
            }
          }
        }
      }
    }

    stage('Browser Tests') {
      agent {
        kubernetes {
          label "${KUBERNETES_LABEL}"
          yaml podTemplate
        }
      }
      steps {
        timeout(time: 5, unit: 'MINUTES') {
          container("website") {
            sh "yarn start"
          }

          container("cypress") {
            sh "yarn test:e2e"
          }
        }
      }
  }
}

In Dockerfile that builds an image I added an ENTRYPOINT

ENTRYPOINT ["bash", "./docker-entrypoint.sh"]

However it seems that it's not executed by the kubernetes plugin.

Am I missing something?

-- Kosmetika
docker
jenkins
jenkins-pipeline
kubernetes
kubernetes-pod

1 Answer

7/11/2019

As per Define a Command and Arguments for a Container docs:

The command and arguments that you define in the configuration file override the default command and arguments provided by the container image.

This table summarizes the field names used by Docker and Kubernetes:

| Docker field name | K8s field name |
|------------------:|:--------------:|
|    ENTRYPOINT     |     command    |
|       CMD         |      args      |

Defining a command implies ignoring your Dockerfile ENTRYPOINT:

When you override the default ENTRYPOINT and CMD, these rules apply:

  • If you supply a command but no args for a Container, only the supplied command is used. The default ENTRYPOINT and the default CMD defined in the Docker image are ignored.
  • If you supply only args for a Container, the default ENTRYPOINT defined in the Docker image is run with the args that you supplied.

So you need to replace the command in your pod template by args, which will preserve your Dockerfile ENTRYPOINT (acting equivalent to a Dockerfile CMD).

-- Eduardo Baitello
Source: StackOverflow