sách gpt4 ai đã đi

jenkins - Jenkins 管道中的条件步骤/阶段

In lại 作者:行者123 更新时间:2023-12-03 05:31:39 27 4
mua khóa gpt4 Nike

仅在构建特定分支时如何运行构建步骤/阶段?

例如,仅当分支名为 deployment 时才运行部署步骤,其他所有内容保持不变。

1 Câu trả lời

在声明性管道语法中执行相同的操作,下面是一些示例:

stage('master-branch-stuff') {
when {
branch 'master'
}
steps {
echo 'run this stage - ony if the branch = master branch'
}
}
<小时>
stage('feature-branch-stuff') {
when {
branch 'feature/*'
}
steps {
echo 'run this stage - only if the branch name started with feature/'
}
}
<小时>
stage('expression-branch') {
when {
expression {
return env.BRANCH_NAME != 'master';
}
}
steps {
echo 'run this stage - when branch is not equal to master'
}
}
<小时>
stage('env-specific-stuff') {
when {
environment name: 'NAME', value: 'this'
}
steps {
echo 'run this stage - only if the env name and value matches'
}
}

更有效的方法即将出现 - https://issues.jenkins-ci.org/browse/JENKINS-41187
另请参阅 - https://jenkins.io/doc/book/pipeline/syntax/#when

<小时>

如果条件不需要 git state 来决定是否运行,则可以设置指令 beforeAgent true 以避免启动代理来运行条件:

when { beforeAgent true; expression { return isStageConfigured(config) } }

Release posttài liệu

<小时>

làm mới
新的 WHEN 子句
Trích dẫn:https://jenkins.io/blog/2018/04/09/whats-in-declarative

equals - Compares two values - strings, variables, numbers, booleans -and returns true if they’re equal. I’m honestly not sure how we missedadding this earlier! You can do "not equals" comparisons using the not{ equals ... } combination too.

changeRequest - In its simplest form, this will return true if thisPipeline is building a change request, such as a GitHub pull request.You can also do more detailed checks against the change request,allowing you to ask "is this a change request against the masterbranch?" and much more.

buildingTag - A simple condition that just checks if the Pipeline isrunning against a tag in SCM, rather than a branch or a specificcommit reference.

tag - A more detailed equivalent of buildingTag, allowing you to checkagainst the tag name itself.

关于jenkins - Jenkins 管道中的条件步骤/阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37690920/

27 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com