我有什么
我正在尝试使用两种不同的代理来运行我的詹金斯管道。我想在同一个代理上执行某些流程,但到目前为止我无法执行此操作,因为代理定义只有 2 个选项:我可以在管道顶部执行,或者我可以将代理定义到每个阶段。我有这个:
pipeline{
agent none
stages {
stage("Unit Testing"){
agent { label 'maven-build-slave' }
steps{
}
}
stage('Sonar Scanner - Quality Gates') {
agent { label 'maven-build-slave' }
steps{
}
}
stage("Integration"){
agent { label 'integration-slave' }
steps{
}
}
stage('SoapUI') {
agent { label 'integration-slave' }
steps{
}
}
}
}
在这种情况下,主要问题是即使代理相同,代码也会在每个阶段被拉取。
我想要什么
我想要这样的东西:
pipeline{
agent none
stages {
agent { label 'maven-build-slave' }
stage("Unit Testing"){
steps{
}
}
stage('Sonar Scanner - Quality Gates') {
steps{
}
}
agent { label 'integration-slave' }
stage("Integration"){
steps{
}
}
stage('SoapUI') {
steps{
}
}
}
}
但上面的定义失败了,所以我想知道是否有人知道使用同一代理运行多个阶段的方法。
查看新内容(2018 年 7 月)声明式管道 1.3 中的连续阶段 https://jenkins.io/blog/2018/07/02/whats-new-declarative-piepline-13x-sequential-stages/:
使用相同的代理、环境或选项运行多个阶段
虽然顺序阶段功能最初是由希望在并行分支中拥有多个阶段的用户驱动的,但我们发现能够将多个阶段与相同的代理、环境、时间等分组在一起还有很多其他用途。
例如,如果您在管道中使用多个代理,但希望确保使用相同代理的阶段使用相同的工作区,则可以使用带有代理指令的父阶段,然后使用其内的所有阶段stage 指令将在同一个工作区中的同一个执行器上运行。
pipeline {
agent none
stages {
stage("build and test the project") {
agent {
docker "our-build-tools-image"
}
stages {
stage("build") {
steps {
sh "./build.sh"
}
}
stage("test") {
steps {
sh "./test.sh"
}
}
}
post {
success {
stash name: "artifacts", includes: "artifacts/**/*"
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)