'jenkins clone and zip repository
i'm currently new to jenkins and i'm trying clone the repo and create a zip and finally upload to s3.
But i'm currently stuck with zip as the default folder location of clone file is /var/lib/jenkins/<project-view>
def getFilename() {
char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray()
StringBuilder sb = new StringBuilder(3)
Random random = new Random();
for (int i = 0; i < 3; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
}
String randomString = sb.toString();
def now = new Date().format("yyyyMMdd")
String output = now + randomString
return output
}
pipeline {
agent any
environment {
FILENAME = getFilename()
}
stages {
stage("Zip"){
steps{
script{
echo "Creating zip archive ${env.FILENAME}.zip"
zip archive: true, dir: '', glob: '', zipFile: "${env.FILENAME}.zip"
archiveArtifacts artifacts: "${env.FILENAME}.zip", fingerprint: true
}
}
}
stage('Upload to AWS') {
steps {
withAWS(region:'eu-west-2',credentials:'7b42d7b6-f11b-41b6-8c14-61dafbd256c7') {
sh 'echo "Uploading content with AWS creds"'
s3Upload(pathStyleAccessEnabled: true, payloadSigningEnabled: true, file: "${env.FILENAME}.zip", bucket:'elasticbeanstalk-eu-west-2-246342104703')
}
}
}
}
}
i tried with providing specific dir to zip /var/lib/jenkins/<project-view>, but was unable to zip the file, any help for this newbie here 🙂. thanks in advance
Solution 1:[1]
I guess your issue is that the S3 command is being executed in a different place from where the zip file is located. Try adding this:
dir('location to your zip') {
after steps {. This will ensure that the withAWS command runs in the same directory as your zip file, and it should be able to find the zip.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | M B |
