Reputation: 65
Goal: Use a declarative Jenkins pipeline to download an artifact from Artifactory, run a test, and set a property value of the artifact in Artifactory based on the test result.
Trouble area: How to set artifact properties of existing artifacts using the Artifactory plugin in a Jenkins pipeline?
Some of the code:
pipeline {
stages {
stage("Load") {
steps {
// Get the firmware from Artifactory
script {
def artServer = Artifactory.newServer url: '~~~'
def downloadSpecInline = """{
"files": [
{
"pattern": "${artRepo}/*thing-*${artBuildNo}*-class.zip",
"recursive": "true",
"flat": "true"
}
]
}"""
def artifactBuildInfo = artServer.download(downloadSpecInline)
// Unknown part
doSomeTest()
artifactBuildInfo.setProperty qa.level, awesome
}
}
}
}
}
Upvotes: 3
Views: 950
Reputation: 47
You could just use the plugin.
def server = Artifactory.server "${_artifactoryServer}" def propsSpec = """{ "files": [ { "pattern": "${my_repo}/*/*/${_filename}" } ] }""" server.setProps spec: propsSpec, props: "${_property}=${_value}", failNoOp: true
One thing to be careful of: If you don't specify a filename, ie. it is zero length, the API will write the property to every artifact in the repo.
Upvotes: 0