0

Here's what I'm trying:

I have a build job and a deployment job. I want to trigger deployments using the build job's build numbers. I'm having trouble incorporating this into a Jenkins pipeline. So first, I created a freestyle project in which I added an active choices parameter with the following groovy script.

return jenkins.model.Jenkins.instance.getJob("BuildJob").builds.findAll{it.result == hudson.model.Result.SUCCESS}.collect{ "$it.number" }

And this properly populates the drop-down values with the values from the build job.

However, when I use this same groovy statement in the pipeline script under the properties parameters section, the drop-down just goes into the error handler block.

Below is the pipeline script I'm using (env.BuildNum used against referencedParameters and in the groovy statement is the value of build job number from the other job (build)). From my understanding the script is unable to locate this value and it goes into the fallback script. But what I can't seem to understand is why does the same script work in a freestyle project but not in a pipeline.

properties([
    parameters([
        [$class: 'CascadeChoiceParameter', 
            choiceType: 'PT_SINGLE_SELECT',
            description: 'Select a choice',
            filterLength: 1,
            filterable: true,
            name: 'Build Number',
            referencedParameters: env.BuildNum,
            script: [$class: 'GroovyScript',
                fallbackScript: [
                    classpath: [], 
                    sandbox: false, 
                    script: 'return ["ERROR"]'
                ],
                script: [
                    classpath: [], 
                    sandbox: false, 
                    script: """
                        return jenkins.model.Jenkins.instance.getJob('Siebel_Build_Master').builds.findAll{ it.result == hudson.model.Result.SUCCESS }.collect{ "$env.BuildNum" }
                    """
                ]
            ]
        ]
    ])
])

pipeline {
    agent any
    (rest of the script)

I'm relatively new to Jenkins, so please let me know if there's any more information needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.