Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在shell(Jenkinsfile)中获取用户输入数据_Jenkins_Groovy_Jenkins Pipeline - Fatal编程技术网

如何在shell(Jenkinsfile)中获取用户输入数据

如何在shell(Jenkinsfile)中获取用户输入数据,jenkins,groovy,jenkins-pipeline,Jenkins,Groovy,Jenkins Pipeline,我试图通过Jenkinsfile获取用户输入,但我不能在shell中使用它。代码如下: def userInput = timeout(time:60, unit:'SECONDS') {input( id: 'userInput', message: 'URL Required', parameters: [ [$class: 'TextParameterDefinition', defaultValue: '', description: 'URL', name: 'u

我试图通过Jenkinsfile获取用户输入,但我不能在shell中使用它。代码如下:

def userInput =  timeout(time:60, unit:'SECONDS') {input(
     id: 'userInput', message: 'URL Required', parameters: [
     [$class: 'TextParameterDefinition', defaultValue: '', description: 'URL', name: 'url'],
    ])
  }

node{
        echo "Env jsfsjaffwef:"+userInput) //this works
        echo "${userInput}" //but this does not
        sh '''
          python test.py ${userInput}
        '''
}

以下是我在Jenkins 2.62上的作品:

def userInput =  input(
     id: 'userInput', message: 'URL Required', parameters: [
     [$class: 'TextParameterDefinition', defaultValue: '', description: 'URL', name: 'url'],
    ])

node('master') {
    sh "echo userInput is: ${userInput}"
}

以下是我在Jenkins 2.62上的作品:

def userInput =  input(
     id: 'userInput', message: 'URL Required', parameters: [
     [$class: 'TextParameterDefinition', defaultValue: '', description: 'URL', name: 'url'],
    ])

node('master') {
    sh "echo userInput is: ${userInput}"
}
注意:变量将在双引号(
“.”“
”)或多行变量(
)中替换,但不能在单引号(
“…”
,分别为
“…”
)中替换。因此
sh
步骤不应该替换它,上面的
echo应该正确地替换它

def userInput=超时(时间:60,单位:秒){input(
id:'userInput',消息:'URL Required',参数:[
[$class:'TextParameterDefinition',defaultValue:'',description:'URL',name:'URL'],
])
}
节点{
echo“Env jsfsjaffwef:+userInput)//这很有效
echo“${userInput}”//这以前也应该起作用
嘘
python test.py${userInput}
"""
}
因此,请确保您完全应用了正确的引号,而不仅仅是将其替换为人们在这里建议的引号。

请注意:变量将被替换为双引号(
)、
、或多行变量(
)、
)、而不是单引号(
)、
。因此,不应更换
sh
步骤,上面的
echo
应正确安装

def userInput=超时(时间:60,单位:秒){input(
id:'userInput',消息:'URL Required',参数:[
[$class:'TextParameterDefinition',defaultValue:'',description:'URL',name:'URL'],
])
}
节点{
echo“Env jsfsjaffwef:+userInput)//这很有效
echo“${userInput}”//这以前也应该起作用
嘘
python test.py${userInput}
"""
}

因此,请确保您完全应用了正确的引号,而不是将其替换为人们建议的引号。

我尝试使用类似的方法,但对我无效:sh''echo'${userInput}''''如果删除${userInput}周围的引号会发生什么情况?我尝试使用类似的东西,但对我不起作用:sh''echo'${userInput}'''如果删除${userInput}周围的引号会发生什么?你真的确定
echo'${userInput}'
不起作用吗?顺便说一句,什么“不起作用”?你真的确定
echo“${userInput}”
不起作用吗?顺便说一句,“不起作用”是什么?