Jenkins 声明式管道,从 Artifactory 下载最新上传(构建)并获取属性
Jenkins declarative pipe, download latest upload (build) from Artifactory and get properties
非常欢迎对这个小问题提出任何建议! :)
下载最新版本工作正常,但对象不包含任何属性。
是否可以从下载的版本中获取属性?
目标是获取一个带有预定义值的输入框,显示以前的版本,即 "R1G",并为用户提供编辑该值的选项,即 R2A 或任何其他值,或者仅中止(中止意味着将没有版本)。
用户还可以选择不执行任何操作,这将导致超时并最终中止.
我要
- 从 Artifactory 存储库下载最新版本
- 将 build.number 存储在 "def prev_build"
中
- 在要更新的用户输入中显示 prev_build(自定义编号)
'''一些代码
echo 'Publiching Artifact.....'
script{
def artifactory_server_down=Artifactory.server 'Artifactory'
def downLoad = """{
"files":
[
{
"pattern": "reponame/",
"target": "${WORKSPACE}/prev/",
"recursive": "false",
"flat" : "false"
}
]
}"""
def buildInfodown=artifactory_server_down.download(downLoad)
//Dont need to publish because I only need the properties
//Grab the latest revision name here and use it again
echo 'Retriving revision from last uploaded build.....'
env.LAST_BUILD_NAME=buildInfodown.build.number
//Yes its a map and I have tried with ['build.number'] but the map is empty
}
echo "Previous build name is $env.LAST_BUILD_NAME" //Will not contain the old (latest)
''' 片段结束
输出为 null 或我给 var 的默认值,而不是预期的版本号。
是的,首先您要下载的工件中应该存在这些属性。
build.number 等是工件 buildinfo.json 文件的一部分。这些不是属性,而是某种元数据。此信息将在 artifactory 的 "Builds" 菜单下可见。 Select 回购和内部版本号。
最后 column/tab 会有构建信息。单击它 - 此文件将包含您需要的与工件对应的所有信息。
build.number 和其他信息将 pushed/uploaded 由 CI 制作。
例如,在 Jenkins 的情况下,尝试推送到人工制品时有一个可用选项 "Capture and publish build info" --> 这一步完成工作
非常感谢您的帮助。
我看到你的建议有效,但当我得到你的答案时,我已经实施了另一个同样有效的解决方案
我正在使用可用的查询语言。
https://www.jfrog.com/confluence/display/RTF/Artifactory+Query+Language
就在管道文件中的管道声明之前,我添加了
def artifactory_url = 'https://lote.corp.saab.se:8443/artifactory/api/search/aql'
def artifactory_search = 'items.find({ "repo":"my_repo"},{"@product.productNumber":
{"$match":"produktname"}}).sort({"$desc":["created"]})'
pipeline
{
和...
stage('Get latest revision') {
steps {
script {
def json_text = sh(script: "curl -H 'X-JFrog-Art-Api:${env.RECIPE_API_KEY}' -X POST '${artifactory_url}' -d '${artifactory_search}' -H 'Content-Type: text/plain' -k", returnStdout: true).trim()
def response = readJSON text: json_text
VERSION = response.results[0].path;
echo "${VERSION}"
println 'using each & entry'
response[0].each{ entry ->
println 'Key:' + entry.key + ', Value:' +
entry.value
}
}
}
}
stage('Do relesase on master')
{
when
{
branch "master"
}
options {
timeout(time: 1, unit: 'HOURS')
}
steps {
script{
RELEASE_SCOPE = input message: 'User input
required', ok: 'Ok to go?!',
parameters: [
choice(name: 'RELEASE_TYPE', choices:
'Artifactory\nClearCaseAndArtifactory\nAbort',
description: 'What is the release scope?'),
string(name: 'VERSION', defaultValue:
VERSION, description: '''Edit release name please!!''',
trim: false)
]
}
echo 'Build both RPM and Zip packages'
... gradlew -Pversion=${RELEASE_SCOPE['VERSION']} clean buildPackages"
script {
def artifactory_server = Artifactory.server 'Artifactory'
def buildInfo = Artifactory.newBuildInfo()
def uploadSpec = """{
"files":[
{
"pattern": "${env.WORKSPACE}/prodname/release/build/distributions/prodname*.*",
"target": "test_repo/${RELEASE_SCOPE['VERSION']}/",
"props": "product.name=ProdName;build.name=${JOB_NAME};build.number=${env.BUILD_NUMBER};product.revision=${RELEASE_SCOPE['VERSION']};product.productNumber=produktname"
}
]
}"""
println(uploadSpec)
artifactory_server.upload(uploadSpec)
}
}
}
非常欢迎对这个小问题提出任何建议! :)
下载最新版本工作正常,但对象不包含任何属性。 是否可以从下载的版本中获取属性?
目标是获取一个带有预定义值的输入框,显示以前的版本,即 "R1G",并为用户提供编辑该值的选项,即 R2A 或任何其他值,或者仅中止(中止意味着将没有版本)。 用户还可以选择不执行任何操作,这将导致超时并最终中止.
我要
- 从 Artifactory 存储库下载最新版本
- 将 build.number 存储在 "def prev_build" 中
- 在要更新的用户输入中显示 prev_build(自定义编号)
'''一些代码
echo 'Publiching Artifact.....'
script{
def artifactory_server_down=Artifactory.server 'Artifactory'
def downLoad = """{
"files":
[
{
"pattern": "reponame/",
"target": "${WORKSPACE}/prev/",
"recursive": "false",
"flat" : "false"
}
]
}"""
def buildInfodown=artifactory_server_down.download(downLoad)
//Dont need to publish because I only need the properties
//Grab the latest revision name here and use it again
echo 'Retriving revision from last uploaded build.....'
env.LAST_BUILD_NAME=buildInfodown.build.number
//Yes its a map and I have tried with ['build.number'] but the map is empty
}
echo "Previous build name is $env.LAST_BUILD_NAME" //Will not contain the old (latest)
''' 片段结束
输出为 null 或我给 var 的默认值,而不是预期的版本号。
是的,首先您要下载的工件中应该存在这些属性。
build.number 等是工件 buildinfo.json 文件的一部分。这些不是属性,而是某种元数据。此信息将在 artifactory 的 "Builds" 菜单下可见。 Select 回购和内部版本号。
最后 column/tab 会有构建信息。单击它 - 此文件将包含您需要的与工件对应的所有信息。
build.number 和其他信息将 pushed/uploaded 由 CI 制作。
例如,在 Jenkins 的情况下,尝试推送到人工制品时有一个可用选项 "Capture and publish build info" --> 这一步完成工作
非常感谢您的帮助。 我看到你的建议有效,但当我得到你的答案时,我已经实施了另一个同样有效的解决方案
我正在使用可用的查询语言。 https://www.jfrog.com/confluence/display/RTF/Artifactory+Query+Language 就在管道文件中的管道声明之前,我添加了
def artifactory_url = 'https://lote.corp.saab.se:8443/artifactory/api/search/aql'
def artifactory_search = 'items.find({ "repo":"my_repo"},{"@product.productNumber":
{"$match":"produktname"}}).sort({"$desc":["created"]})'
pipeline
{
和...
stage('Get latest revision') {
steps {
script {
def json_text = sh(script: "curl -H 'X-JFrog-Art-Api:${env.RECIPE_API_KEY}' -X POST '${artifactory_url}' -d '${artifactory_search}' -H 'Content-Type: text/plain' -k", returnStdout: true).trim()
def response = readJSON text: json_text
VERSION = response.results[0].path;
echo "${VERSION}"
println 'using each & entry'
response[0].each{ entry ->
println 'Key:' + entry.key + ', Value:' +
entry.value
}
}
}
}
stage('Do relesase on master')
{
when
{
branch "master"
}
options {
timeout(time: 1, unit: 'HOURS')
}
steps {
script{
RELEASE_SCOPE = input message: 'User input
required', ok: 'Ok to go?!',
parameters: [
choice(name: 'RELEASE_TYPE', choices:
'Artifactory\nClearCaseAndArtifactory\nAbort',
description: 'What is the release scope?'),
string(name: 'VERSION', defaultValue:
VERSION, description: '''Edit release name please!!''',
trim: false)
]
}
echo 'Build both RPM and Zip packages'
... gradlew -Pversion=${RELEASE_SCOPE['VERSION']} clean buildPackages"
script {
def artifactory_server = Artifactory.server 'Artifactory'
def buildInfo = Artifactory.newBuildInfo()
def uploadSpec = """{
"files":[
{
"pattern": "${env.WORKSPACE}/prodname/release/build/distributions/prodname*.*",
"target": "test_repo/${RELEASE_SCOPE['VERSION']}/",
"props": "product.name=ProdName;build.name=${JOB_NAME};build.number=${env.BUILD_NUMBER};product.revision=${RELEASE_SCOPE['VERSION']};product.productNumber=produktname"
}
]
}"""
println(uploadSpec)
artifactory_server.upload(uploadSpec)
}
}
}