I am using Jenkins Declarative Pipeline to automate my build process. We want to publish our artifacts to a remote JFrog repository only if certain conditions (Sonar,Checkmarx) pass.
After a bit of research, I found that Artifactory plugin is useful for this. But I am unable to find any document on how to integrate in declarative pipeline. Below is the code snippet from Jenkinsfile
stages{
stage('Pre-Build'){
steps{
script{
def server = Artifactory.server 'LocalJfrog'
def rtGradle = Artifactory.newGradleBuild()
rtGradle.resolver server: server, repo: 'gradle-dev-local'
rtGradle.deployer server: server, repo: 'gradle-release-local'
rtGradle.useWrapper = true
}
}
}
}
The conditional publish is not possible with above code as I cannot reuse the server variable even if I disable auto publish.