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
Jenkins 使用sh运行脚本时出现文件问题_Jenkins_Jenkins Pipeline - Fatal编程技术网

Jenkins 使用sh运行脚本时出现文件问题

Jenkins 使用sh运行脚本时出现文件问题,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,我有以下文件 def ARTIFACTS_JOB_ID; def ARTIFACTS_URL; node('CentOs') { checkout scm stage('Example') { echo 'Download artifacts' sh 'curljson --header "PRIVATE-TOKEN: tdzis3" "https://gitlab-sample.com/api/v4/projects/63/jobs" >

我有以下文件

def ARTIFACTS_JOB_ID;
def ARTIFACTS_URL;

node('CentOs') {
    checkout scm
    stage('Example') {
        echo 'Download artifacts'
        sh 'curljson  --header "PRIVATE-TOKEN: tdzis3" "https://gitlab-sample.com/api/v4/projects/63/jobs" > jobs.json'
        ARTIFACTS_JOB_ID = sh(returnStdout: true, script: 'python GetID.py').trim()
        ARTIFACTS_URL = "https://gitlab-sample.com/api/v4/projects/63/jobs/${ARTIFACTS_JOB_ID}/artifacts"
        echo "======> $ARTIFACTS_URL"
        sh 'echo $ARTIFACTS_URL'
        sh 'curl --output artifacts.zip --header "PRIVATE-TOKEN: tdzis3" "$ARTIFACTS_URL"'
    }
}
在试图获取工件时,它正在呼叫

'curl--output artifacts.zip--header“PRIVATE-TOKEN:tdzis3”“”
带有空url

同样地

echo "======> $ARTIFACTS_URL" //works fine
sh 'echo $ARTIFACTS_URL' // shows empty string, tried with ${ARTIFACTS_URL} aswell.
有没有一种方法可以按如下方式运行它(这样我就不必使用
sh

如果没有
sh
我在执行以下操作时出现无效语法错误
curljson--header

您试过了吗

sh "curl --output artifacts.zip --header 'PRIVATE-TOKEN: tdzis3' '{$ARTIFACTS_URL}'"
?

对于多个sh命令,也可以使用

sh """
curl command here
cd command next 
etc
"""

变量声明
ARTIFACTS\u URL=”https://...“
是一个Groovy全局变量。因此,
sh
步骤自然不能将其作为shell变量使用

您需要在
sh
步骤中使用双引号而不是单引号将命令包装为
sh“echo$ARTIFACTS\u URL”
,以便Groovy将其作为Groovy变量插入

sh """
curl command here
cd command next 
etc
"""