代码之家  ›  专栏  ›  技术社区  ›  J4N

BlueOcean没有要求我的一些jenkins多分支参数

  •  0
  • J4N  · 技术社区  · 7 年前

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

    当我尝试为这个分支启动多分支管道时,我需要很多参数,但没有添加新的参数。

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

    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')
        }
    }
    

    我没有得到任何请求的“新”参数是“runTests”。

    我该怎么做才能得到它们?我试着重启,什么也没改变。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Rob Porter    6 年前

    根据 documentation example , parameters {} 需要事先申报 stages{} scripted pipelines are serially executed from top to bottom

    另外,如果这只是添加到一个jenkins文件,你可能需要运行它两次,它不会知道第一次有参数要处理。