Jenkins声明性管道并行构建
我需要两个构建与jenkins声明性管道并行运行。 为避免脚本管道中的生成工作区之间发生冲突,可以使用以下构造:Jenkins声明性管道并行构建,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,我需要两个构建与jenkins声明性管道并行运行。 为避免脚本管道中的生成工作区之间发生冲突,可以使用以下构造: lock('some_lock') { checkout git 'gitrepo' build } 在声明性管道中,不会直接调用checkout步骤,所以即使我们这样做锁 steps { lock('some_lock') { build here ongoing } } 我们可能会遇到这样的情况:构建A正在构建,
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'
}
}
}
}
}