Unix 将多个参数从Jenkins文件传输到shell脚本

Unix 将多个参数从Jenkins文件传输到shell脚本,unix,jenkins,groovy,jenkins-pipeline,jenkins-groovy,Unix,Jenkins,Groovy,Jenkins Pipeline,Jenkins Groovy,我有一个Jenkins文件,它接受用户输入的多个参数。我需要将这些参数传输到shell脚本 pipeline { options { skipDefaultCheckout() timestamps() } parameters { string(name: 'FILENAME', defaultValue: 'tmp', description: 'Enter the file name that needs to be

我有一个Jenkins文件,它接受用户输入的多个参数。我需要将这些参数传输到shell脚本

pipeline {
    options {
        skipDefaultCheckout()
        timestamps()
    }
    parameters {
        string(name: 'FILENAME', defaultValue: 'tmp', description: 'Enter the file name that needs to be copied')
        string(name: 'DB_NAME', defaultValue: 'xyz', description: 'Enter the database that needs to be created')
        string(name: 'VERSION', defaultValue: '', description: 'Enter the DB name version')
        choice(name: 'RUN', choices: 'Migrate Data', description: 'Data migration')
    }
    agent {
        node { label 'ci-build-node-01' }
    }
    triggers {
        pollSCM('H/5 * * * *')
    }
    stages {
        stage('Clean & Clone') {
            steps {
                cleanWs()
                checkout scm
            }
        }
        stage('Run the shell script On-prem'){
            steps {
                configFileProvider([configFile(fileId: 'env-on-prem', targetLocation: '.env')]) {
                    sh  '''
                            export \$(egrep -v '^#' .env)
                            /deploy/deploy.sh

                        '''
                }
            }
        }
    }
}


我可以知道如何将多个参数(如
${FILENAME}
${DB_NAME}
${VERSION}
传输到shell脚本deploy.sh?

以访问您将使用的参数:
${params.}
,因此在您的情况下是
${params.FILENAME}
传入shell脚本的示例:

sh "deploy.sh ${params.FILENAME} ${params.DB_NAME}"

根据您的回答@altaf,整个脚本将是:

pipeline {
    options {
        skipDefaultCheckout()
        timestamps()
    }
    parameters {
        string(name: 'FILENAME', defaultValue: 'tmp', description: 'Enter the file name that needs to be copied')
        string(name: 'DB_NAME', defaultValue: 'xyz', description: 'Enter the database that needs to be created')
        string(name: 'VERSION', defaultValue: '', description: 'Enter the DB name version')
        choice(name: 'RUN', choices: 'Migrate Data', description: 'Data migration')
    }
    agent {
        node { label 'ci-build-node-01' }
    }
    triggers {
        pollSCM('H/5 * * * *')
    }
    stages {
        stage('Clean & Clone') {
            steps {
                cleanWs()
                checkout scm
            }
        }
        stage('Run the shell script On-prem'){
            steps {
                configFileProvider([configFile(fileId: 'env-on-prem', targetLocation: '.env')]) {
                    sh  '''
                            export \$(egrep -v '^#' .env)
                            /deploy/deploy.sh ${params.FILENAME} ${params.DB_NAME} ${params.VERSION}

                        '''
                }
            }
        }
    }
}

像这样?

yes in
steps{sh”deploy.sh${params.FILENAME}${params.DB_NAME}}
我没有使用这种格式,请检查上面的问题/答案。@merilstack:是的,这是一个如何将多个参数作为参数传递给shell脚本以及如何使用
${params}访问参数的示例
访问方式在任何格式下都将保持不变。@merilstack您得到的错误是什么?我无法访问这些参数@altaf,一旦我使用$${params.}从Jenkinsfile传输这些参数,我应该使用shell脚本中的${params.}或${}来访问它们吗?