jenkins克隆和zip存储库



我目前是jenkins的新手,我正在尝试克隆repo并创建一个zip,最后上传到s3。

但我目前被zip卡住了,因为克隆文件的默认文件夹位置是/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')
}
}
}
}
}

我试着为zip/var/lib/jenkins/<project-view>提供特定的目录,但无法压缩文件,这对这个新手有任何帮助。提前感谢

我想您的问题是S3命令的执行位置与zip文件所在的位置不同。尝试添加以下内容:

dir('location to your zip') {

在CCD_ 3之后。这将确保withAWS命令在与zip文件相同的目录中运行,并且它应该能够找到zip。

最新更新