[英]Jenkins declarative pipeline create custom workspace for parallel builds
[英]Jenkins declarative pipeline parallel builds
我需要有两个与jenkins声明式管道并行运行的构建。 为了避免脚本化管道中的构建工作空间之间发生冲突,可以使用以下构造:
lock('some_lock') {
checkout git 'gitrepo'
build
}
在声明性管道中,不会直接调用checkout步骤,因此即使我们像这样进行锁定,
steps {
lock('some_lock') {
build here ongoing
}
}
我们可能会遇到以下情况:构建A正在构建,构建B正在等待锁定,但它仍将执行检出,因为在声明性管道中,您无需指定检出何时发生。 可以避免吗?
我知道理论上詹金斯在这种情况下不应该使用相同的工作空间。 但不幸的是,它有时会发生。
我认为声明式管道中遇到的问题是默认情况下自动发生的“声明式:签出SCM”阶段。 如果是这样,您可以通过关闭此功能并手动签出源代码来解决问题,如下所示:
pipeline {
agent { label 'docker' }
options {
skipDefaultCheckout true // this is how you avoid the 'Declarative: Checkout SCM' stage
}
stages {
stage('commit_stage') {
steps {
lock('some_lock') {
checkout scm // this is how you replicate what 'Declarative: Checkout SCM' does as a step
echo 'build stuff here'
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.