【问题标题】:Jenkins parallel pipeline does not work as expectedJenkins 并行管道无法按预期工作
【发布时间】:2018-06-15 09:23:24
【问题描述】:

我有一个带有并行阶段的 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: []
                        }
                    }
                }
            }
        }

换句话说,有没有办法将当前工作区复制到另一个工作区,并在并行阶段的一个阶段使用新创建的工作区?如果这是可能的,那么它应该可以解决我的问题。

【问题讨论】:

    标签: jenkins jenkins-pipeline


    【解决方案1】:

    我确实通过将每个并行阶段的完整工作区复制到另一个工作区来解决此问题。 在 ws(){} 块中运行阶段时,它会与其他阶段隔离运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-28
      • 2020-01-01
      • 2020-01-03
      • 2019-12-13
      • 1970-01-01
      • 2017-05-05
      • 2018-04-05
      • 1970-01-01
      相关资源
      最近更新 更多