I am using Jenkins Pipline and Groovy script to download a zip on slave machine of jenkins.
Following is my code:
pipeline {
agent { label '<my slave label>' }
stage('Download') {
steps {
script {
def url = "<server url>"
def processDownload = ['bash', '-c', "curl -g -k --noproxy \"*\" -o <output-dir> \"${url}\""].execute()
processDownload.waitFor()
def processUnzip = ['bash', '-c', "7z e lwbs.zip"].execute()
processUnzip.waitFor()
}
}
}
}
I am getting following error:
Warning: Failed to create the file Warning:
output-dir/newFile.zip: No such file or directory
I have checked following:
curl
command using command prompt, it run's successfully.jenkins slave
Is there anything I am missing?
Any help is appreciated. Thank you.
After long hours of research, I found out the bash command triggered using following command
def processDownload = ['bash', '-c', "curl -g -k --noproxy \"*\" -o <output-dir> \"${url}\""].execute()
Jenkins will always execute it on Master.
When I change it to normal shell command, Jenkins is correctly executing it on slave machine. Moreover to unzip, I used Pipeline Utility Steps
plugin which provides unzipping functionality which gets executed on slave. Following is my working code:
stage('Download') {
steps {
script {
url = "<server url>"
sh "curl -k --noproxy \"*\" -o \"<output-dir>\" \"${url}\""
unzip(dir: '', glob: '', zipFile: 'fileName.zip')
}
}
}