如何在Jenkins管道脚本中使用wget和几个参数

时间:2017-08-22 08:22:40

标签: jenkins groovy jenkins-pipeline

我必须使用wget命令发送请求。 我原来的shell脚本如下:

  

wget --post-data   ' PARAMS = $ PARAMS&安培; URI = $ URI&安培;专案编号= $专案编号&安培; suiteId = $ suiteId&安培;的runid = $的runid&安培; projectNameValue = $ projectNameValue&安培; caseIdStart = $ caseIdStart&安培; caseIdEnd = $ caseIdEnd&安培; mockFlag = $ mockFlag&#39 ;   http://10.139.11.150:9999/SEAutoTest2/testrun/testrail

此wget命令将多个参数传输到页面。 我使用管道语法来实现管道代码,但是它不会起作用。 参数无法从String Parameters中实现。

这是我的jenkins configration屏幕截图。

Here is my jenkins configration screenshot.

这是我的管道代码:

node('dev_ci_env_migu') {
properties([parameters([string(defaultValue: ' ', description: ' ', name: 'VERSION'), string(defaultValue: ' ', description: ' ', name: 'SVN_ADDRESS'), string(defaultValue: ' ', description: ' ', name: 'TEST_ENV'), string(defaultValue: ' ', description: ' ', name: 'USER'), string(defaultValue: ' ', description: ' ', name: 'PASSWD'), string(defaultValue: ' ', description: ' ', name: 'PACKAGE_PATH'), string(description: '', name: 'params'), string(defaultValue: ' ', description: ' ', name: 'projectNameValue'), string(defaultValue: ' ', description: ' ', name: 'uri'), string(defaultValue: ' ', description: ' ', name: 'projectId'), string(defaultValue: ' ', description: ' ', name: 'suiteId'), string(defaultValue: ' ', description: ' ', name: 'runId'), string(defaultValue: ' ', description: ' ', name: 'caseIdStart'), string(defaultValue: ' ', description: ' ', name: 'caseIdEnd'), string(defaultValue: ' ', description: ' ', name: 'mockFlag')]), pipelineTriggers([])])
withEnv(['INTERNAL_PATH=/data/path']) {
    //get code from svn
    stage 'Checkout'
    checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[credentialsId: '', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: '$SVN_ADDRESS']], workspaceUpdater: [$class: 'UpdateUpdater']])
    //compile & generate war
    stage 'Build'
    sh '''source /home/migu/.bashrc
cd $WORKSPACE
mvn clean install -DskipTests'''
stage('Automation Test'){
input 'Is test automation preparation job done?'
sh 'wget --post-data 'params=${params}&uri=${uri}&projectId=${projectId}&suiteId=${suiteId}&runId=${runId}&projectNameValue=${projectNameValue}&caseIdStart=${caseIdStart}&caseIdEnd=${caseIdEnd}&mockFlag=${mockFlag}\' http://10.139.11.150:9999/SEAutoTest2/testrun/testrail'
}
    }
}

1 个答案:

答案 0 :(得分:1)

在大多数脚本语言中,当您需要变量替换时使用双引号(“),而当您不想要变量替换时使用单引号(')。

如果您调整代码以使用"代替',那么它应该有效。可能需要对外部单引号进行特殊处理:

未测试:

sh "wget --post-data \"params=${params}&uri=${uri}&projectId=${projectId}&suiteId=${suiteId}&runId==${runId}&projectNameValue=${projectNameValue}&caseIdStart=${caseIdStart}&caseIdEnd=${caseIdEnd}&mockFlag=${mockFlag}\" http://10.139.11.150:9999/SEAutoTest2/testrun/testrail"