【问题标题】:Jenkins declarative pipe, download latest upload (build) from Artifactory and get propertiesJenkins 声明性管道,从 Artifactory 下载最新上传(构建)并获取属性
【发布时间】:2019-06-12 09:29:02
【问题描述】:

非常欢迎对这个小问题提出任何建议! :)

下载最新版本可以正常工作,但该对象不包含任何属性。 是否可以从下载的版本中获取属性?

最好的方法是获取一个带有预定义值的输入框,显示以前的版本,即“R1G”,并为用户提供将值编辑为 R2A 或任何其他值或仅中止的选项(中止意味着将有没有版本)。 用户还可以选择什么都不做,否则会导致超时并最终中止。

我想要

  • 从 Artifactory repo 下载最新版本
  • 将 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 的默认值,而不是预期的版本号。

【问题讨论】:

    标签: jenkins-pipeline artifactory jenkins-groovy jfrog-cli


    【解决方案1】:

    是的,首先属性应该存在于您尝试下载的工件中。

    build.number 等是工件的 buildinfo.json 文件的一部分。这些不是属性,而是某种元数据。此信息将在工件的“构建”菜单下可见。选择存储库和内部版本号。

    在最后一列/选项卡将有 buildinfo。单击它 - 此文件将包含您需要的与工件相对应的所有信息。

    build.number 和其他信息将由 CI 推送/上传到工件。

    例如,在 Jenkins 的情况下,当尝试推送到工件“捕获和发布构建信息”时,有一个可用选项-->这一步完成了工作

    【讨论】:

      【解决方案2】:

      非常感谢您的帮助。 我看到您的建议有效,但是当我得到您的答案时,我已经实施了另一个也很有效的解决方案

      我正在使用可用的查询语言。 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)
                                      }
      
                                  }
                              }                       
      

      【讨论】:

        猜你喜欢
        • 2017-12-03
        • 2020-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-05
        • 2019-04-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多