Reputation: 4805
I'm trying to save a spidered URL into a variable and using it later on in a curl
call:
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"
But Jenkins displays binary data and exits with:
�����+ --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
It looks like Jenkins Pipeline doesn't recognize the --output
parameter.
What am I doing wrong?
EDIT: By moving the --output installable.zip
parameter before the URL it works. But why?
Upvotes: 0
Views: 362
Reputation: 6869
It looks like your installableURL
has a carriage return at the end, so that your curl
turns into two commands:
curl ${installableURL} # this is the first command terminated by \n
--output installable.zip && unzip installable.zip -d installable # this is the second command
The second command, naturally, fails.
Usually, we get rid of the trailing newline with trim()
, e.g.
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()
Upvotes: 1