I'm trying to get Jenkins CSRF crumb to call the job from Rest Api in Azure DevOps pipeline, but I can't assign the output of curl to a variable to pass to the next task.
So first thing I tried was to create a variable in a variable group and assign the output to it, but seems bash task doesn't get this - it gave exit code 127.
jenkins.crumb is a variable from the group.
$(jenkins.crumb)=$(curl -u $(jenkins.user):$(jenkins.token) -s '$(jenkins.url)/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
Second thing I tried is setvariable in inline command like below, but it doesn't give an error, but no value is assigned. (temp, crumb are all empty in the log.)
variables:
- group: Myvariables-group
pool:
vmImage: 'ubuntu'
steps:
- task: Bash@3
name: GetCSRFcrumb
inputs:
targetType: 'inline'
script: |
temp=$(curl -u $JENKINS_USER:$JENKINS_TOKEN -s '$JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
echo "##vso[task.setvariable variable=crumb]$temp"
echo "$temp"
echo $temp
- task: Bash@3
inputs:
targetType: 'inline'
script: |
echo "$(crumb)"
echo "$CRUMB"
I'd like to avoid creating shell script file or curl output as a file. (maybe last resort if there is no other way.)
$tempis also empty so the issue is in the curl, did you check that your get an output? - Shayki Abramczykjenkins.user,jenkins.tokenandjenkins.url, so I used$JENKINS_USERas the document suggests as bash env, but there was no error at all, but empty result in that line. Now I just tried$(jenkins.user)which is a direct reference, then it looks working as it is. - kevmando