BlueOcean不需要我的某些詹金斯多分支参数

时间:2018-06-26 08:47:17

标签: jenkins jenkins-pipeline multibranch-pipeline jenkins-blueocean

我最近修改了我的分支机构的Jenkinsfile(目前,这个jenkins分支只有一个分支)。

当我尝试为该分支启动多分支管道时,我请求了很多参数,但没有添加的新参数。

如果我进入Jenkins(不是BlueOcean),在配置中我会看到它们,如果我从那里开始构建,我也会看到它们。

这是我的Jenkins文件:

pipeline {
    agent {
        node{
            label 'windows-node'
            customWorkspace "D:\\ws\\${env.BRANCH_NAME}"            
        }
    }
    options{
        skipDefaultCheckout()
    }
    triggers{
        pollSCM 'H 23 * * *'
    }
    stages {        
        stage('Initialization started'){
            steps{
                echo "Job parameters:\n\t- Build X86: ${params.buildX86}\n\t- Build X64: ${params.buildX64}\n\t- Commit Version changes: ${params.commitVersionChanges}.${env.BUILD_NUMBER}\n\t- Setup Version: ${params.version}\n\t- Setup Configuration: ${params.setupConfiguration}\nCurrent repository: ${workspace}"                 
            }
        }
        stage('Checkout'){
            steps{
                echo "Custom checkout: ${env.BRANCH_NAME}"
                checkout scm
            }
        }
        stage('ABC Solution Pre-build') {
            steps {
                changeAsmVer "${params.version}.${env.BUILD_NUMBER}"
                bat 'nuget.exe restore Solution\\ABC.sln'
                powershell 'ContinuousIntegration\\Scripts\\ChangeBindingVersion.ps1 "HDAPluginNet4" "Src\\Clients\\OpcServer\\Xms.OpcHda.Server\\HDANSrv.Net4.exe.config"'             
            }           
        }
        stage('Preparing SonarQube'){
            when{
                expression{ params.runTests == true && env.BRANCH_NAME == 'develop'}
            }

            steps{
                withSonarQubeEnv('XYZ SonarQube') {
                    script{
                        def sqScannerMsBuildHome = tool 'SonarQube.Runner-3.0'
                    }
                    bat "${sqScannerMsBuildHome}\\SonarQube.Scanner.MSBuild.exe begin /k:ABC /n:ABC /v:${params.version}.${env.BUILD_NUMBER} /d:sonar.host.url=%SONAR_HOST_URL% /d:sonar.login=%SONAR_AUTH_TOKEN% /d:sonar.cs.nunit.reportsPaths=TestResult.xml /d:sonar.cs.dotcover.reportsPaths=dotcover.html"      
                }
            }
        }
        stage('Build ABC Solution') {
            steps{
                bat "\"${tool 'MSBUILD15'}\" Solution\\ABC.sln /p:Configuration=${params.setupConfiguration} /p:Platform=\"Any CPU\" /t:Rebuild"
            }
        }
        stage('ABC Solution Pre-setup') {
            when{
                expression{ params.buildX64 == true || params.buildX86 == true}
            }
            steps{
                bat "\"Src\\Obfuscation\\XmsApplicationsObfuscation\\Release\\obfuscationProcess.cmd\" \"${workspace}\" \"${workspace}\\output\\dotfuscator.zip\" \"XXXXXXXX\""
                bat "Doc\\BuildDocumentation.bat"
            }
        }
        stage('X64 Setup build') {
            when{
                expression{ params.buildX64 == true}
            }
            steps{
                bat "\"${tool 'MSBUILD15'}\" Solution\\SetupWix.sln /p:Configuration=${params.setupConfiguration} /p:Platform=x64 /t:Rebuild /p:Version=\"${params.version}.${env.BUILD_NUMBER}\""
                bat "move SetupWix\\SetupWix\\bin\\Release\\en-us\\ABCSetup.msi SetupWix\\SetupWix\\bin\\Release\\en-us\\ABCSetup_64_bit.msi"
            }
        }

        stage('X86 Setup build') {
            when{
                expression{ params.buildX86 == true}
            }
            steps{
                bat "\"${tool 'MSBUILD15'}\" Solution\\SetupWix.sln /p:Configuration=${params.setupConfiguration} /p:Platform=x86 /t:Rebuild /p:Version=\"${params.version}.${env.BUILD_NUMBER}\""
                bat "move SetupWix\\SetupWix\\bin\\Release\\en-us\\ABCSetup.msi SetupWix\\SetupWix\\bin\\Release\\en-us\\ABCSetup_32_bit.msi"
            }
        }

        stage('Post-setup'){
            when{
                expression{ params.buildX64 == true || params.buildX86 == true}
            }
            steps{
                powershell 'ContinuousIntegration\\Scripts\\MoveSetups.ps1'
            }
        }
        stage('Commit version change'){
            when{
                expression{ params.commitVersionChanges == true}
            }
            steps{
                bat 'git add "./*AssemblyInfo.*"'
                bat 'git commit -m "Assembly infos changed by Jenkins"'
                bat "git push origin HEAD:${env.BRANCH_NAME}"
            }
        }
        stage('Testing'){
            when{
                expression{ params.runTests == true}
            }
            steps{
                bat 'dotcover.exe analyze ContinuousIntegration/DotCoverConfig.xml'   
                nunit testResultsPattern: 'TestResult.xml'              
            }
        }
        stage('Finishing SonarQube'){
            when{
                expression{ params.runTests == true && env.BRANCH_NAME == 'develop'}
            }
            steps{
                withSonarQubeEnv('XYZ SonarQube') {
                    script{
                        def sqScannerMsBuildHome = tool 'SonarQube.Runner-3.0'
                    }
                    bat "${sqScannerMsBuildHome}\\SonarQube.Scanner.MSBuild.exe end"   
                }
            }
        }
    }
    post{
        failure {
            emailext body: "<b>Error while excuting the following job</b><br><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br>Build URL: ${env.BUILD_URL}", mimeType: 'text/html', recipientProviders: [brokenTestsSuspects(), brokenBuildSuspects()], subject: "ERROR CI: Project name -> ${env.JOB_NAME}"
        }
        unstable{
            emailext body: "<b>Error while excuting the following job</b><br><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br>Build URL: ${env.BUILD_URL}", mimeType: 'text/html', recipientProviders: [brokenTestsSuspects(), brokenBuildSuspects()], subject: "ERROR CI: Project name -> ${env.JOB_NAME}"
        }
    }
    parameters {
        booleanParam(name: 'buildX86', defaultValue: false, description: 'Build for X86 platform')
        booleanParam(name: 'buildX64', defaultValue: true, description: 'Build for X64 platform')
        booleanParam(name: 'commitVersionChanges', defaultValue: false, description: 'Commit the version changes')
        booleanParam(name: 'runTests', defaultValue: false, description: 'Run unit tests')      
        string(name: 'version', defaultValue: '3.6.0', description: 'Version of the setup to build')
        choice(name: 'setupConfiguration', choices: '''Release
Debug''', description: 'Setup configuration to use')
    }
}

我没有得到任何请求的“新”参数(仅在BlueOcean中)是“ runTests”。

我该怎么做才能得到它们?我尝试重新启动,没有做任何更改。

1 个答案:

答案 0 :(得分:0)

根据documentation exampleparameters {}必须在stages{}之前声明,否则,由于scripted pipelines are serially executed from top to bottom,它不知道要在模板变量中放置什么值。 >

此外,如果只是将其添加到Jenkinsfile中,则可能需要运行两次,它不会第一次知道要处理的参数。