Jenkinsfile Configuration - ambitus/artifactory-vault GitHub Wiki

This guide assumes that you want to interface with Artifactory using a Jenkinsfile.

☑️ Prerequisites:

  • JFrog Artifactory server
  • Artifactory repository
  • Artifactory user
  • Permissions giving the user that you want to use to interface with Artifactory from Jenkins permission to modify a JFrog Artifactory repository
  • Artifactory plugin installed on Jenkins
  • Artifactory server configured in Jenkins at "Manage Jenkins/Configure System"

 

How to Configure Your Jenkinsfile

If the infrastructure is all setup, you can move forward with configuring your Jenkinsfile:

  • Define the Artifactory server

    define at the top of your Jenkinsfile.

    def server = Artifactory.server '<your artifactory server ID>'
  • Define an upload specification

    define as an environment variable inside the environment section of your Jenkinsfile.

    UPLOAD_SPEC = """{
        "files": [
            {
                //MANDATORY: file(s) from the Jenkins server that you want to upload to Artifactory
                "pattern": "dir/<file(s)>",
                
                //OPTIONAL: used to apply filters to results when downloading file(s) from Artifactory later
                "props" : "key1=value1;key2=value2",
                
                //MANDATORY: place you want to put the file(s) inside Artifactory
                "target": "artifactory-repository/dir/"
            }
        ]
    }"""
  • Define a download specification

    define as an environment variable inside the environment section of your Jenkinsfile.

    DOWNLOAD_SPEC = """{
        "files": [
            {
                //MANDATORY: file(s) that you want to download from Artifactory 
                "pattern": "artifactory-repository/<file(s)>", 
                
                //OPTIONAL: apply a filter when downloading file(s) from Artifactory
                //NOTE: the file(s) you want must have these props
                "props" : "key1=value1;key2=value2",
                
                //MANDATORY place you want to put the downloaded file(s) on Jenkins server
                "target": "dir/" 
            }
        ]
    }"""
  • Define a stage in your pipeline where you upload file(s) to Artifactory using your upload specification

    stage('upload file(s) to Artifactory') {
        steps {
            echo 'Uploading file(s) to Artifactory'
            script {
                server.upload uploadSpec //PERFORM UPLOAD
            }
        }
    }
  • Define a stage in your pipeline where you download files from Artifactory using your download specification.

    stage('download file(s) from Artifactory') {
        steps {
            echo 'Downloading file(s) from Artifactory'
            script {
                server.download spec: downloadSpec //PERFORM DOWNLOAD
            }
        }
    }
  • Run a Jenkins build and fix any errors in your Jenkinsfile that may have caused the build to fail.

  • After the Jenkins build is complete, check the console output and the Artifactory repository from the Artifactory UI to verify that all of the new Artifactory specific operations were successful. If you get any unusual SSL protocol errors, please see the the Jenkins Configuration wiki.

 

If you wish to do more advanced things with your file specifications, view the JFrog Artifactory documentation on file specifications here.

⚠️ **GitHub.com Fallback** ⚠️