简体   繁体   English

如何在 jenkins 管道中构建和上传 docker-compose 文件

[英]How to build and upload docker-compose file inside jenkins pipeline

I need to build a docker image using docker-compose.yaml file and then I need to push it on dockerhub.我需要使用 docker-compose.yaml 文件构建 docker 映像,然后我需要将其推送到 dockerhub 上。 I used following command to build Dockerfile and push it to dockerhub with jenkins docker plugin.我使用以下命令构建 Dockerfile 并使用 jenkins docker 插件将其推送到 dockerhub。

stage('Building image and Push') {
      steps{
        script {
          customImage = docker.build("my-image:${env.BUILD_ID}")
          customImage.push()
        }
      }
    }

Is there a similar method to write this kind of command to build and push docker-compose file?有没有类似的方法来编写这种命令来构建和推送 docker-compose 文件?

PS: I heard about about a plugin called Docker compose build step . PS:听说有个插件叫Docker compose build step Can I do same as above with this plugin?我可以用这个插件做同样的事情吗?

This does not seem supported in a scripted pipeline.脚本化管道似乎不支持此功能。

Using purely a declarative pipeline on an agent based on the docker-compose image (so with docker-compose preinstalled), I suppose you can shell script those commands directly:在基于docker-compose映像的代理上使用纯粹的声明性管道(因此预装了docker-compose ),我想您可以 shell 直接编写这些命令:

stage('Build Docker Image') {  
    steps{                     
    sh 'docker-compose build'     
    echo 'Docker-compose-build Build Image Completed'                
    }           
}

And then login to DockerHub and push, as described in " Simple Jenkins Declarative Pipeline to Push Docker Image To Docker Hub "然后登录 DockerHub 并推送,如“ Simple Jenkins 声明式管道将 Docker 映像推送到 Docker Hub ”中所述

stage('Login to Docker Hub') {          
    steps{                          
    sh 'echo $DOCKERHUB_CREDENTIALS_PSW | sudo docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'                     
    echo 'Login Completed'      
    }           
}
stage('Push Image to Docker Hub') {         
    steps{                            
 sh 'sudo docker push <dockerhubusername>/<dockerhubreponame>:$BUILD_NUMBER'           
echo 'Push Image Completed'       
    }            
}

A manual approach, since an " agent docker-compose " is not directly available (you have docker agent docker/dockerfile/kubernetes , but no docker-compose option)手动方法,因为“ agent docker-compose ”不直接可用(您有 docker agent docker/dockerfile/kubernetes ,但没有docker-compose选项)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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