詹金斯搭建_詹金斯多分支并行管道

詹金斯搭建

After a long break, I am back again. Let’s move forward with another Jenkins job type so-called multibranch pipeline. In this post, I will focus on parallel execution syntax for the CD chain via Jenkins.

休息片刻后,我又回来了。 让我们继续进行另一种詹金斯工作类型的所谓多分支管道。 在本文中,我将重点介绍通过Jenkins的CD链的并行执行语法。

Following tools I’ve used:
* Jenkins
* Docker
* CMake

You most probably work on a multi-branch project where you not directly developing under the master/main branch. To keep the main/production branch always stable we avoid pushing new code there. In my demo will use a C++ project where build, test, and all QA processes triggered by CMake.

您很可能在一个多分支项目中工作,而您没有直接在master / main分支下进行开发。 为了使main / production分支始终保持稳定,我们避免在此处推送新代码。 在我的演示中,将使用一个C ++项目,在其中构建,测试和所有由CMake触发的QA流程。

Each parallel stage will run its docker container and we will make always out of source build to keep source code clean. As you might know, you can run all Linux commands in the Jenkins pipeline. This will power us to work as on Linux machine. At some point, there are some differences based on syntax because Jenkinsfile has to be written in the Groovy language. Nonetheless the groovy allows you to use the same syntax as well by adding

每个并行阶段都将运行其docker容器,我们将始终脱离源代码构建,以保持源代码干净。 如您所知,您可以在Jenkins管道中运行所有Linux命令。 这将使我们能够像在Linux机器上一样工作。 在某些时候,基于语法存在一些差异,因为必须使用Groovy语言编写Jenkinsfile。 尽管如此,通过添加groovy,您也可以使用相同的语法

#!/bin/bash
echo "hello world"
'''

The project structure looks as below:

项目结构如下:

├───.vscode
└───cpp-project
├───.vscode
├───CMakeLists.txt
├───cmake
├─── code-coverage.cmake
├─── sanitizer.cmake
├─── package-settings.cmake
├───src
├───Jenkinsfile
└───test

The Jenkinsfile looks:

Jenkinsfile看起来:

//if you have multiple worker define by node('worker1')node(){checkout scm//Define where you docker image located
def String dockerImage = “docker//Add docker argument
def String dockerArgs = “-v ${WORKSPACE}:/tmp/project -w /tmp/project”//define your environment
def String devEnv = “CONAN_USER_HOME=/tmp/conan/ CONAN_NON_INTERACTIVE=1 CCACHE_DIR=/tmp/ccache/”//here will run three stage parallelparallel (‘Release build’: { docker.image(dockerImage).inside(dockerArgs){
sh “mkdir -p /tmp/build-release”
echo "build release process here"
}},‘Address Sanitizer’: {docker.image(dockerImage).inside(dockerArgs){
sh “mkdir -p /tmp/build-sanitizer “
echo "Do the sanitizer here"
}},'Coverage-Stage' : docker.image(dockerImage).inside(dockerArgs){
sh “mkdir -p /tmp/coverage “
echo "Do the coverage here"}})//And when all stage successfully done then add new non parallel stage as Deploymentstage(‘Deploy Debian Package’) {
docker.image(dockerImage).inside(dockerArgs){
echo "Do the deployment process"//if this master branch then deploy itif(env.BRANCH_NAME == “master”) {echo "This is master branch will be deployed"
}
else{
echo “Skipping upload, only allowed on master.”
}
}
}

Sure you can be extended as you like by adding new parallel jobs or sequential steps. I simply give syntax on Jenkinsfile.

当然,您可以通过添加新的并行作业或顺序步骤来扩展自己。 我只是在Jenkinsfile上给出语法。

Next post I will share source code and set up the entire CI/CD chain.

在下一篇文章中,我将分享源代码并设置整个CI / CD链。

翻译自: https://medium.com/swlh/jenkins-multibranch-parallel-pipeline-355ffe0677ba

詹金斯搭建

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值