我需要创建一个Jenkins Job,它能够将所有这3种事件传递到此示例管道中
pipeline {
agent {
node {
label 'pipeline-docker-agent'
}
}
stages {
stage('Build Branches and PR') {
/*Test, vet, build and discard*/
when { anyOf{ branch "*"; changeRequest() } }
steps {
echo 'test,vet and build'
}
}
stage('Publish master Artifact') {
when { branch 'master' }
steps {
echo 'Then Push the artifact, since its the master..'
echo 'Then Tag the SCM as required'
}
}
stage('Deploy to Stage') {
when { tag "rc-*" }
steps {
echo 'Downloading the artifact'
echo 'Deploying to STAGEing'
}
}
stage('Deploy prod') {
when { tag "release-*" }
steps {
echo 'Downloading the artifact'
echo 'Deploying to Prod'
}
}
}
该怎么做,我应该安装所有插件?
来自drone.io,circleCI等现代CI工具。詹金斯管道被宣传为等同于这些现代CI工具。试图在詹金斯身上复制类似的行为。
不幸的是,从Jenkins管道迁移到上述CI工具之一在我当前的组织中不是一个选择。我们的平台/基础架构人员对古老的工具和技术很着迷。叹!。乱跑。任何帮助将不胜感激。
一个更具体的用例是,我想针对所有新事件而不是过去的事件触发自动构建。 (其中一个曾尝试触发已关闭PR的插件,并使用了较旧的Tag等)
GitHub Enterprise是SCM。
尝试使用多分支管道配置
答案 0 :(得分:0)
找到了一个适合我账单的Jenkins插件
https://github.com/KostyaSha/github-integration-plugin
该插件以及多分支管道作业配置让我创建了一个可以处理Commit,PR和Tag事件的管道
我不得不稍微更改管道声明语法
pipeline {
agent {
node {
label 'pipes-docker-agent'
}
}
stages {
stage('Build Branches and PR') {
/*Test, vet, build */
when { expression { !env.GITHUB_TAG_NAME } }
steps {
echo 'test,vet and build'
}
}
stage('Publish master Artifact') {
/*Jenkins have a problem with the intuitive syntax */
when { expression { env.BRANCH_NAME && env.BRANCH_NAME.toString().equals('master') } }
steps {
echo 'Then Push the above-built artifact, since its the master. Need to have similar strategy for Hotfix branches'
echo 'Then Tag the SCM as required'
}
}
stage('Deploy to Stage') {
when {expression { env.GITHUB_TAG_NAME && env.GITHUB_TAG_NAME.toString().startsWith("rc-") } }
steps {
echo 'Downloading the artifact'
echo 'Deploying to STAGEing'
}
}
/* I think its wise to move this as another Job*/
stage('Deploy prod') {
when {expression { env.GITHUB_TAG_NAME && env.GITHUB_TAG_NAME.toString().startsWith("release-") } }
steps {
echo 'Downloading the artifact'
echo 'Deploying to Prod'
}
}
}
}