gpt4 book ai didi

jenkinsfile 管道按代理分组阶段

转载 作者:行者123 更新时间:2023-12-02 21:14:09 25 4
gpt4 key购买 nike

我有什么

我正在尝试使用两种不同的代理来运行我的 Jenkins 管道。我想在同一个代理上执行某些流程,但到目前为止我无法执行此操作,因为代理定义只有 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 月)Sequential Stages in Declarative Pipeline 1.3 :

Running Multiple Stages with the Same agent, or environment, or options

While the sequential stages feature was originally driven by users wanting to have multiple stages in parallel branches, we’ve found that being able to group multiple stages together with the same agent, environment, when, etc has a lot of other uses.

For example, if you are using multiple agents in your Pipeline, but would like to be sure that stages using the same agent use the same workspace, you can use a parent stage with an agent directive on it, and then all the stages inside its stages directive will run on the same executor, in the same workspace.

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/**/*"
}
}
}

关于jenkinsfile 管道按代理分组阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48082711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com