Jenkins Pipeline Utility Steps - zip zipFile

前端 未结 4 555
没有蜡笔的小新
没有蜡笔的小新 2021-01-11 15:30

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

P

相关标签:
4条回答
  • 2021-01-11 15:36

    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/**/*.*
    
    0 讨论(0)
  • 2021-01-11 15:56

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

    0 讨论(0)
  • 2021-01-11 16:01

    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

    0 讨论(0)
  • 2021-01-11 16:02

    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/
                '''
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题