簡體   English   中英

Jenkins 管道 - Jenkinsfile 如何觸發 docker

[英]Jenkins Pipeline - how does Jenkinsfile tigger docker

我有一個構建在使用 Jenkins 管道的構建服務器上的應用程序。 我知道該應用程序構建在 docker 容器內。 部分stage('Build')中的Jenkinsfile包含以下行:

agent { label 'someDockerImageName' }

如何檢查引擎蓋下發生的情況,即使用了哪些 docker 命令? 我猜這里可以使用docker pulldocker run 我還沒有找到關於 Jenkins 的任何相關信息(控制台 Output,管道步驟)。

看來您的代理語法錯誤。 通常,為了在聲明性管道中使用 docker 代理,您的語法應如下所示:

agent {
    docker {
        image 'ubuntu'
    }
}

一旦您的管道使用 docker 代理,您應該會在控制台日志中看到 docker 命令。 例如,這是一個簡單的管道及其日志記錄 output:

管道

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

日志

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM