Jenkins Pipeline Utility Steps - zip zipFile

别等时光非礼了梦想. 提交于 2019-12-19 03:08:22

问题


I am trying to zip the folders which are created as output of my jenkins pipeline job using pipeline script. By googling i came to know the Jenkins

Pipeline Utility Steps - zip zipFile

https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-zip-code-create-zip-file to zip folders/files but could not get exact pipeline syntax to zip.

In my job workspace, I have a folder by name 'Test' which has 2 sub folders as 'Test1', 'Test2'. Each sub folder will have .dll files. So, I would like to zip entire 'Test' folder with all subfolder.

node(Jenkinks_1)
{
    echo "ZIP"
    zip zipFile: 'Test.zip', dir:'C:\\workspace\\Build_Sample\\Test'
    echo "END - ZIP"
}

Below are the Console Output from Jenkins:

Started by user XXXXX
[Pipeline] node
Running on Jenkinks_1 in C:\workspace\Build_Sample
[Pipeline] {
[Pipeline] echo
ZIP
[Pipeline] echo
END - ZIP
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

Looking for some guidance to zip the folders using pipeline syntax. Appreciate your inputs.

I wanted to zip some files as output of my jenkins pipeline job


回答1:


First, try the same operation in stages and step, as in here:

pipeline {
    agent any
    stages {
        stage ('push artifact') {
            steps {
                sh 'mkdir archive'
                sh 'echo test > archive/test.txt'
                zip zipFile: 'test.zip', archive: false, dir: 'archive'
                archiveArtifacts artifacts: 'test.zip', fingerprint: true
            }
        }
        ...
    }

It uses archiveArtifacts to record the result.

If using an absolute path does now work, try a relative one ('..')

As seen by the OP Sri, zip zipFile is part of, and requires the JENKINS Pipeline Utility Steps Plugin.
See "Implemented Steps".


Regarding the syntax to be used for multi-criteria file selection, NicolasW notes in the comments that the documentation is vague: "use glob ant-style syntax"...
He got it to work though, with a basic coma separated syntax.
E.g.

zip zipFile: 'test.zip', archive: false, glob: 'config-/**/,scripts/**/*.*



回答2:


Was able to Zip after installing the Pipeline Utility Steps plugin.




回答3:


I came across this because zip was ... not installed on the host.
Reminder to self : If you need zip, install it first.

sudo yum install zip




回答4:


you can just use sh (jenkins server need install zip);

 sh '''
            zip -r  algo.zip algo
 '''

pipeline script like this

node {
    stage('Clean'){
        cleanWs()
    }
    stage('Checkout') {
       git branch: 'develop', url: 'ssh://user@ip:29418/prj.git'
    }
    stage('Zip') {
        dir('algo-python') {
            sh '''
            zip -r  algo.zip algo
            '''
       }
    }
    stage('Upload zip'){
        dir('algo-python') {
            sh '''
                source /etc/profile
                export HADOOP_USER_NAME=dev
                hdfs dfs -put -f algo.zip /user/dev/zipfile/
            '''
        }
    }
}


来源:https://stackoverflow.com/questions/48352443/jenkins-pipeline-utility-steps-zip-zipfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!