Upload from Jenkinsfile to Artifactory (Declarative Pipeline)

Posted on by Kim

#!groovy

pipeline {
    agent any {

    stages {
        stage('Clone') {
            steps {
                echo 'Clone...'
                git branch: 'master'
                    credentialsId: 'jenkins-ssh',
                    url: 'ssh://git@bitbucket.ccc.net:7999/xxx/test.git'
            }
        }

        stage('Build')
            steps {
                echo 'Build...'
                script {
                    def server = Artifactory.server 'AFN' // Setup in Jenkins : Manage Jenkins -> Configure System -> Artifactory (Server ID)
                    def buildInfo = Artifactory.newBuildInfo()
                    buildInfo.env.capture = true
                    def rtMaven = Artifactory.newMavenBuild()
                    rtMaven.tool = 'M3' // Setup in Jenkins : 
                    rtMaven.deployer releaseRepo:'libs-release-local', snapshotRepo: 'libs-snapshot-local', server: server
                    rtMaven.resolver releaseRepo:'libs-release', snapshotRepo: 'libs-snapshot', server: server

                    rtMaven.run pom: 'pom.xml', goals: 'clean install', buildInfo: buildInfo

                    buildInfo.retention maxBuilds: 10, maxDays: 7, deleteBuildArtifacts: true
                    server.publishBuildInfo buildInfo
                }
            }
        }
    }
    post {
        success {
            archiveArtifacts artifacts: '**target/*.jar', fingerprint: true
        }
    }
}

0 Responses to "Upload from Jenkinsfile to Artifactory (Declarative Pipeline)":