Curl Jenkins管道:旋度未识别--输出参数

Curl Jenkins管道:旋度未识别--输出参数,curl,jenkins-pipeline,Curl,Jenkins Pipeline,我试图将一个spidered URL保存到一个变量中,并在以后的curl调用中使用它: script { installableURL = getCommunityInstallableURL(device, os) if (installableURL == null) { installableURL = sh script: """ wget --spider -Fr -np "https://line

我试图将一个spidered URL保存到一个变量中,并在以后的
curl
调用中使用它:

script {
    installableURL = getCommunityInstallableURL(device, os)
    if (installableURL == null) {
        installableURL = sh script: """
        wget --spider -Fr -np "https://lineageos.mirrorhub.io/full/${device}/" 2>&1 \
            | grep '^--' | awk '{ print \$3 }' | grep "${os}.*\\.zip\$" | sort -nr | head -n 1
        """, returnStdout: true
    }
}
sh "curl ${installableURL} --output installable.zip && unzip installable.zip -d installable"
但是Jenkins显示二进制数据并退出:

�����+ --output installable.zip
/home/jenkins/agent/workspace/build@tmp/durable-6c1d3ef5/script.sh: 2: /home/jenkins/agent/workspace/build@tmp/durable-6c1d3ef5/script.sh: --output: not found
Jenkins管道似乎无法识别
--output
参数。 我做错了什么


编辑:在URL工作之前移动
--output installable.zip
参数。但是为什么呢?

看起来您的
installableURL
末尾有一个回车符,因此
curl
会变成两个命令:

curl ${installableURL} # this is the first command terminated by \n

 --output installable.zip && unzip installable.zip -d installable # this is the second command
第二个命令自然会失败

通常,我们用
trim()
来摆脱尾随的换行符,例如

installableURL = sh (
   script: """
        wget --spider -Fr -np "https://lineageos.mirrorhub.io/full/${device}/" 2>&1 \
            | grep '^--' | awk '{ print \$3 }' | grep "${os}.*\\.zip\$" | sort -nr | head -n 1
        """,
   returnStdout: true).trim()