如何从Jenkins声明性管道中的URL填充Jenkins构建参数值

如何从Jenkins声明性管道中的URL填充Jenkins构建参数值,jenkins,parameters,jenkins-pipeline,Jenkins,Parameters,Jenkins Pipeline,如何从URL填充choice参数? 我可以下载并保存环境变量中的值,但如果我尝试使用它,则会出现错误: 若我在parameters部分中用choicesURL替换choicesFoo,我会得到错误 这是我的管道: def choicesFoo = ['x','y'] pipeline{ agent { node { label 'LinuxOpt' } } environment{ choic

如何从URL填充choice参数? 我可以下载并保存环境变量中的值,但如果我尝试使用它,则会出现错误: 若我在parameters部分中用choicesURL替换choicesFoo,我会得到错误

这是我的管道:

def choicesFoo = ['x','y']

pipeline{
    agent { 
        node { 
            label 'LinuxOpt'
        } 
    }
    environment{
        choicesUrl = sh(script: "curl http://example.com/foo.txt", returnStdout: true)
    }
     parameters {
        choice(name: 'CHOICE', choices: choicesFoo, description: 'Pick an option')
    }
    stages {
        stage('Build') {
            steps {
                sh 'echo run build'
                 sh "echo ${choicesUrl}"
            }
        }
    }
}

您可以在声明管道之前尝试准备
选项,例如:

def choicesUrl 

node('Prepare Choices') {
    stage('Get Choices') {
        choicesUrl = sh(
            script: "curl http://example.com/foo.txt", 
            returnStdout: true).trim()
    }
}


pipeline{
    agent { node { label 'LinuxOpt' } }
    parameters {
        choice(name: 'CHOICE', choices: choicesUrl, description: 'Pick an option')
    }
    stages {
        stage('Build') {
            steps {
                sh 'echo run build'
                sh "echo ${choicesUrl}"
            }
        }
    }
}

您需要使用完整的
参数
类来提供动态选择。