简体   繁体   中英

Jenkins Pipeline - how does Jenkinsfile tigger docker

I have an application which is built on the build server which uses Jenkins Pipeline. I know that the application is built inside the docker container. Jenkinsfile in the section stage('Build') contains the following line:

agent { label 'someDockerImageName' }

How can I check what happens under the bonnet, ie which docker commands are used? I guess that there can be used docker pull and docker run . I haven't found any relevant information on the Jenkins (Console Output, Pipeline Steps).

It seems your agent syntax is wrong. Typically in order to use a docker agent in a declarative pipeline, your syntax should be like follows:

agent {
    docker {
        image 'ubuntu'
    }
}

Once your pipeline is using a docker agent, you should see the docker commands in the console logs. For example, here's a simple pipeline and its logging output:

Pipeline

pipeline {
    agent {
        docker {
            image 'ubuntu'
        }
    }
    stages {
        stage('foo') {
            steps {
                sh 'echo bar'
            }
        }
    }
}

Logs

Started by user Kthompso
Resume disabled by user, switching to high-performance, low-durability mode.
[Pipeline] Start of Pipeline
[Pipeline] node
Running on jenkinsagent in /var/lib/jenkins/workspace/sample_docker_project
[Pipeline] {
[Pipeline] isUnix
[Pipeline] sh
+ docker inspect -f . ubuntu
.
[Pipeline] withDockerContainer
jenkinsagent does not seem to be running inside a container
$ docker run -t -d -u 1001:1001 -w /var/lib/jenkins/workspace/sample_docker_project -v /var/lib/jenkins/workspace/sample_docker_project:/var/lib/jenkins/workspace/sample_docker_project:rw,z -v /var/lib/jenkins/workspace/sample_docker_project@tmp:/var/lib/jenkins/workspace/sample_docker_project@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** ubuntu cat
$ docker top 5f130a2429b6081736a17edf16eef62f4a8fa85cf498f0b338fa8f500ac53d00 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (foo)
[Pipeline] sh
+ echo bar
bar
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 5f130a2429b6081736a17edf16eef62f4a8fa85cf498f0b338fa8f500ac53d00
$ docker rm -f 5f130a2429b6081736a17edf16eef62f4a8fa85cf498f0b338fa8f500ac53d00
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM