我有一个带并行阶段的Jenkins声明性管道。 在并行阶段,每个环境都会更改配置文件,并且将构建和部署war包文件。
当我运行并行管道时,它会失败,因为所有更改都在同一目录结构上完成,因此会覆盖另一个并行阶段的所有更改。 如何使管道并行证明。那么它是在他自己的'包含'环境中运行的吗?
我的平行阶段看起来像:
stage('Deploy Staging') {
parallel {
stage('Deploy APAC') {
when {
branch 'develop'
}
steps {
script {
configFileProvider([configFile(fileId: 'bb78f756-623c-412d-8b5d-15756023eb6d', targetLocation: 'src/main/resources/ehcache.xml'), configFile(fileId: 'b48ae55e-5212-4a4f-be6b-e632bb3efe4b', targetLocation: 'src/main/resources/application.properties')]) {
bat 'mvn clean package -Dmaven.test.skip=true'
bat 'move target\\APP-server-*.war APP_APAC.war'
bat 'cd database && migrate.cmd --env=staging_APAC up'
powershell 'Invoke-RestMethod -Uri "http://server/manager/text/deploy?path=/APP_APAC&update=true" -Headers @{Authorization=("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "user", "userpw"))))} -Method PUT -InFile ${PWD}\\APP_APAC.war -ContentType "multipart/form-data" -TimeoutSec 600'
}
//build job: 'APP EMEA Staging', parameters: []
}
}
}
stage('Deploy NASA') {
when {
branch 'develop'
}
steps {
script {
configFileProvider([configFile(fileId: 'bb78f756-623c-412d-8b5d-15756023eb6d', targetLocation: 'src/main/resources/ehcache.xml'), configFile(fileId: '17086c42-6c7f-4fa0-bdbb-8da4d5f276e1', targetLocation: 'src/main/resources/application.properties')]) {
bat 'mvn clean package -Dmaven.test.skip=true'
bat 'move target\\APP-server-*.war APP_NASA.war'
bat 'cd database && migrate.cmd --env=staging_NASA up'
powershell 'Invoke-RestMethod -Uri "http://server/manager/text/deploy?path=/APP_NASA&update=true" -Headers @{Authorization=("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "user", "userpw"))))} -Method PUT -InFile ${PWD}\\APP_NASA.war -ContentType "multipart/form-data" -TimeoutSec 600'
}
//build job: 'APP EMEA Staging', parameters: []
}
}
}
stage('Deploy EMEA') {
when {
branch 'develop'
}
steps {
script {
configFileProvider([configFile(fileId: 'bb78f756-623c-412d-8b5d-15756023eb6d', targetLocation: 'src/main/resources/ehcache.xml'), configFile(fileId: 'e02b3492-6f14-4999-8176-f0533ada5bfd', targetLocation: 'src/main/resources/application.properties')]) {
bat 'mvn clean package -Dmaven.test.skip=true'
bat 'move target\\APP-server-*.war APP_EMEA.war'
bat 'cd database && migrate.cmd --env=staging_EMEA up'
powershell 'Invoke-RestMethod -Uri "http://server/manager/text/deploy?path=/APP_EMEA&update=true" -Headers @{Authorization=("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "user", "userpw"))))} -Method PUT -InFile ${PWD}\\APP_EMEA.war -ContentType "multipart/form-data" -TimeoutSec 600'
}
//build job: 'APP EMEA Staging', parameters: []
}
}
}
}
}
换句话说,有没有办法将当前工作空间复制到另一个工作空间并在并行阶段的一个阶段中使用新创建的工作空间?如果这是可能的,那么它应该解决我的问题。
答案 0 :(得分:0)
我通过在每个并行阶段复制另一个工作区中的完整工作区来解决这个问题。 当运行ws(){}块中的阶段时,它将独立于其他阶段运行。