Jenkinsfile: Build job does not pass parameters

109 views
Skip to first unread message

Adrian Wyssmann

unread,
Dec 15, 2020, 1:35:22 AM12/15/20
to Jenkins Users
I have a shared library which reads parameters from the jenkinsfile so here is the important snippet of the shared library (defaultCiPipelineGeneric.groovy)
def call(body) {
    // evaluate the body block, and collect configuration into the object
    def pipelineParams= [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = pipelineParams
    body()

    pipelineParams = initializePipeline(pipelineParams, pipelineParams.buildType)

    pipeline {
        agent {
            label pipelineParams.nodes
        }
        triggers {
            cron(pipelineParams.schedule)
        }
        options {
            /*
            - daysToKeepStr: history is only kept up to this days.
            - numToKeepStr: only this number of build logs are kept.
            - artifactDaysToKeepStr: artifacts are only kept up to this days.
            - artifactNumToKeepStr: only this number of builds have their artifacts kept.
            */
            buildDiscarder(logRotator(artifactNumToKeepStr: '1', 
                            daysToKeepStr: "${pipelineParams.logdaystokeep}",
                            numToKeepStr: "${pipelineParams.lognumtokeep}"))
            disableConcurrentBuilds()
            timeout(time: pipelineParams.timeout, unit: 'MINUTES')
        }
        tools {
            jdk "${pipelineParams.java}"
            nodejs "${pipelineParams.nodejs}"
        }
        parameters{
            booleanParam(
                defaultValue: false, 
                description: 'Enables debug information in the log',
                name: 'isDebug')
            booleanParam(
                defaultValue: false,
                description: "Marks the build as 'Release' build which triggers defined release commands e.g. `mvn release`",
                name: 'isRelease')
            booleanParam(
                defaultValue: false,
                description: 'Force deployment on deployment nodes as well as run of integration tests - use this parameter with CAUTION as it overrides existing deployments on SIT', 
                name: 'forceDeployment')
        }
        stages {
...

The pipeline is then uses as follows (e.g. in jenkins-pipeline-demo-generic):
library identifier: "pipeline-helper@master"

defaultCiPipelineGeneric {
    nodes               = 'windows-test'
    buildScript         = 'build.groovy'
}


This works fine. I have  an "umbrella" jenkins job (jenkins-pipeline-demo) which trigger this (and other jobs)
library identifier: "pipeline-helper@master"
//def pipelineParams = [:]

pipeline {
   agent {
      label 'devops'
   }
   parameters {
      booleanParam(
         defaultValue: false,
         description: 'Enables debug information in the log',
         name: 'isDebug')
      booleanParam(
         defaultValue: false,
         description: "Marks the build as 'Release' build which triggers defined release commands e.g. `mvn release`",
         name: 'isRelease')
      booleanParam(
         defaultValue: false,
         description: 'Force deployment on deployment nodes as well as run of integration tests - use this parameter with CAUTION as it overrides existing deployments on SIT',
         name: 'forceDeployment')
   }
   stages {
      stage('Build') {
         steps {
            script {
                build job: '../jenkins-pipeline-demo-generic/master'
                    parameters: ([] + params)
                    propagate: propagate
               }
            }
         }
      }
   }
}

So I have a problem as if I trigger the jenkins-pipeline-demo with one of the parameters (e.g. isDebug) this parameter is not passed down.

What I do wrong?


Reply all
Reply to author
Forward
0 new messages