Search code examples
jenkinsjenkins-pipelineartifactoryjenkins-groovy

How to deploy all the content in a folder to Artifactory with similar folder structure through a Jenkins file


We are using Artifactory to store our files. All the files and folders under location ${WORKSPACE}/build/processed/webApps/epmapp/* should be copied to below mentioned target location.

But only files are being copied.

stage('Deploy Artifacts') 
        {
            def targetLocation="epmpbcs-release-local/Platform/PBCSVB/${BRANCH_NAME}/latest/"
            def targetLocationBuildNumber="epmpbcs-release/PBCSVB/${BRANCH_NAME}/${env.BUILD_NUMBER}/"
            stdout = sh(script: 'rm -fv ${WORKSPACE}/buildversion.txt',  returnStdout: true)
            println("Delete buildversion.txt stdout ################ " + stdout + " ####################")
 
            def buildversion = new File("${WORKSPACE}/buildversion.txt")
//            def w = buildversion.newWriter() 
            buildversion<<"PBCSVB Branch:${BRANCH_NAME}, Build Number:${BUILD_NUMBER}"
 
//
            def uploadSpec = """{
                "files": [
                        {
                          "pattern": "${WORKSPACE}/build/processed/webApps/epmapp/*",
                          "target" : "$targetLocation"
                        }
                 ]
                }"""

How can I get folders copied too?


Solution

  • You can't upload files and folders at one time. This is the limitation of uploading part of the artifact. You need to add one more task before uploading the artifact. Add a step to create "epmapp" folder as in .zip or .gzp format and then upload.

    def uploadSpec = """{
                "files": [
                        {
                          "pattern": "epmapp.zip",
                          "target" : "$targetLocation",
                          "recursive": "false"
                        }
                 ]
                }"""
    

    Use this link for more info.