在声明性 Jenkinsfile 之前运行脚本以使用扩展选择参数插件

Ana*_*nco 6 jenkins-pipeline extended-choice-parameter jenkins-declarative-pipeline

我正在尝试运行一个脚本来实例化扩展选择参数变量以在声明性 jenkinsfile 属性部分中使用它,但是我无法在没有步骤的情况下在 jenkinsfile 中运行脚本。我不想将其作为输入步骤或脚本管道来执行。

所以我运行它首先是一个节点步骤,然后是一个管道步骤,如下所示:

import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition

node('MyServer') {

    try {
        def multiSelect = new ExtendedChoiceParameterDefinition(...)   

        properties([ parameters([ multiSelect ]) ])
    }
    catch(error){
        echo "$error"
    }
}

pipeline {

    stages {
        ....
    }
}
Run Code Online (Sandbox Code Playgroud)

它神奇地起作用了!需要注意的是,仅当我之前仅使用管道块运行过构建时。

那么,有没有更好的方法来运行以前的脚本到管道?能够为属性或步骤之外的其他地方创建对象以嵌入脚本块?

hak*_*iri 1

我宁愿选择pipeline 中的参数块

参数指令提供了用户在触发管道时应提供的参数列表。这些用户指定参数的值可通过 params 对象提供给 Pipeline 步骤,请参阅示例了解其具体用法。

pipeline {
    agent any
    parameters {
        string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')

        text(name: 'BIOGRAPHY', defaultValue: '', description: 'Enter some information about the person')

        booleanParam(name: 'TOGGLE', defaultValue: true, description: 'Toggle this value')

        choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something')

        password(name: 'PASSWORD', defaultValue: 'SECRET', description: 'Enter a password')

        file(name: "FILE", description: "Choose a file to upload")
    }
    stages {
        stage('Example') {
            steps {
                echo "Hello ${params.PERSON}"

                echo "Biography: ${params.BIOGRAPHY}"
                echo "Toggle: ${params.TOGGLE}"

                echo "Choice: ${params.CHOICE}"

                echo "Password: ${params.PASSWORD}"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)