Reputation: 358
I am trying to zip a directory in a Jenkins pipeline, my code is similar to this
stages {
stage('ZIP') {
steps {
script {
currentBuild.displayName = "DISPLAY_NAME"
}
// Zip DIRECTORY
sh '''
cd ${WORKSPACE}
zip -r zip_file_name src_dir
'''
}
}
}
I get the following error
@tmp/durable-4423e1f6/script.sh: line 3: zip: command not found
However, when I create another job with execute as a shell option for the build, zip is working fine.
I have tried using zip pipeline utillity plugin, but when I try to access the zip file it is not found.
script {
currentBuild.displayName = "${VERSION}"
zip zipFile: '${zip_file_name}', dir: 'src_dir', overwrite: true
}
Upvotes: 1
Views: 4816
Reputation: 1328
@raviTeja, I guess zip utility is missing in your jenkins agent machine. What is the OS flavour of your Jenkins agent? Lets say if you are using Linux flavours like Redhat, ubuntu.. first you need to install the zip utility in the agent machine. Then alone you can use the zip command in your script
If you are using RedHat flavour in the agent machine
sudo dnf install zip
zip -r zip_file_name src_dir
If you are using ubuntu/debian flavour for jenkins agent
sudo apt install zip
zip -r zip_file_name src_dir
Update:
If you are using Jenkins in the docker container, you can do something similar to the below.
I am guessing you are running ubuntu base image (identify the respective base image Linux flavour and execute the below commands)
docker exec -it <container> /bin/bash
apt-get -y update
apt-get install zip -y
But remember if you delete this container, you are going to loose this set-up. You might have repeat all these steps
Upvotes: 2