詹金斯(Jenkins):在升级版本中使用存档的工件 [英] Jenkins: Use Archived Artifact in Promoted Build

查看:280
本文介绍了詹金斯(Jenkins):在升级版本中使用存档的工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将工件保存为构建的最后一步,并且可以通过以下方式使用它:

I've archived an artifact as the last step of the build and it's available as something like this: https://xxx.ci.cloudbees.com/job/xxx/52/artifact/target/xxx-1.2.1-SNAPSHOT-r8304-20130807-1507-app.zip

如何在促销过程中轻松访问工件?请注意,我需要访问特定的版本,而不是最新的成功版本.

How can I easily access the artifact in my promotion process? Please note that I need to access the specific build, not the latest successful one.

升级过程的目标是将工件复制到S3,我们的部署作业将从该工件进一步对其进行处理.因此,我可能将内部版本52进行开发(将其复制到特定的S3存储桶),然后将内部版本50进行生产,以此类推.

The goal of the promotion process is to copy the artifact to S3 from where our deployment job will further process it. So I might promote build #52 to development (copy it to a specific S3 bucket), later on promote build #50 to production and so on.

理想情况下,我可以在shell脚本中访问工件以重命名文件等.是否存在环境变量来访问构建的归档工件,而我找不到或应该怎么做? $BUILD_URL$JOB_URL已经特定于升级过程,并且没有指向升级工作的shell脚本中的内部版本.

Ideally, I can access the artifact in a shell script to rename the file etc. Is there an environment variable to access the archived artifacts of a build, which I cannot find or how should this be done? $BUILD_URL and $JOB_URL are already specific to the promotion process and don't point to the build itself in shell scripts on the promotion job.

使用复制工件插件,我只能在升级过程中从其他内部版本复制工件,而无需这样做.

With the copy artifact plugin I can only copy artifacts from other builds in the promotion process, which I don't need to do.

推荐答案

我相信我已经找到了解决方案.

I believe I have found the solution.

  • 请勿使用永久链接指定的
  • 使用特定内部版本,并将内部版本号设置为${PROMOTED_NUMBER}
  • Do not use Specified by permalink
  • Use Specific build and set build number to ${PROMOTED_NUMBER}

先决条件

  • 必须安装复制工件插件.
  • 存档要促销使用的工件
    • 构建后操作中添加操作存档工件,然后将要归档的文件设置为您希望升级访问的内容.
    • The Copy Artifact Plugin must be installed.
    • Archive the artifacts you want the promotions to access
      • In Post-build Actions add the action Archive the artifacts and set Files to archive to what ever you want your promotion to access.
      • 在作业配置"中,取消选择丢弃旧版本或确保其设置将保留工件的时间长于您要推广的版本.
      • In the Job Configuration, deselect Discard Old Builds or ensure that its settings will keep the artifacts for as long as you want to promote your builds.

      促销设置:

      像往常一样使用名称和条件设置升级后的内部版本.

      Setup up your promoted build with name and criteria as usual.

      在操作"部分中,添加操作从另一个项目复制工件,并设置这些值.

      In the Actions section add the action Copy artifacts from an other project, and set these values.

      • 项目名称:${PROMOTED_JOB_NAME}
      • 哪个版本:特定版本
      • 内部版本号:${PROMOTED_NUMBER}
      • 要复制的工件:path/to/your/artifacts/**
      • 目标:${BUILD_TAG}
      • Project Name: ${PROMOTED_JOB_NAME}
      • Which Build: Specific Build
      • Build Number: ${PROMOTED_NUMBER}
      • Artifacts to Copy: path/to/your/artifacts/**
      • Target: ${BUILD_TAG}

      然后添加您真正想要执行的操作.例如,添加操作存档工件以保存工件.请记住在路径前面加上${BUILD_TAG},例如${BUILD_TAG}/path/to/your/artifacts/**

      Then add the actions you really want to do. For example add the action Archive the artifacts to save the artifacts. Remember to prefix your paths with ${BUILD_TAG} e.g. ${BUILD_TAG}/path/to/your/artifacts/**

      复制工件

      您现在可能已经知道,促销活动不应期望访问构建工作区的内容.它可能在另一台服务器上执行,并且可能根本无法访问任何工作空间,也无法访问旧版本或更新版本的工作空间.因此,需要将要使用的工件复制到当前工作空间.

      As you probably know by now, the promotion should not expect to have access the the content of the workspace of the build. It might be executed on a different server, and it might have access to no workspace at all or the workspace from an older or newer build. It is therefore required to copy the artifacts you want to use to the current workspace.

      这也是设置 Target 值的原因.工作区可能会被其他构建或产品污染.将目标设置为${BUILD_TAG},通过创建升级过程专用的文件夹,可以防止与工作空间中已有的文件发生任何冲突.

      This is also the reason why the Target value is set. The workspace might be poluted with other builds or promototions. Setting target to ${BUILD_TAG} Prevents any conflicts with files already in the workspace, by creating a folder unique to the promotion process.

      $ {PROMOTED_ *}个变量

      当您声明正常的构建变量时,它们指的是升级过程本身,但是Promoted Build Plugin定义了一些

      As you state the normal build variables refer to the promotion process itself, but The Promoted Build Plugin defines some environment variables referring to the actual build instead.

      永久链接

      在Jenkins上下文中永久链接仅指指向某种类型的最新版本或最新促销的特殊链接.这就是为什么您将始终获得最新版本的原因

      In a Jenkins context permalinks only refers to the special links that points to the latest build of some type or the latest promotion. That is why you will always get the latest version

      在我的Jenkins版本中,下拉列表已替换为文本框.将URL写入特定的版本(例如http://jenkins/job/myjob/59/)是无法识别作为特殊的永久链接之一,并复制

      In my version of Jenkins the dropdown is replaced with a textbox. Writing the URL to a specific build like http://jenkins/job/myjob/59/ is not recognized as one of the special permalinks, and the copying will thus fail.

      这篇关于詹金斯(Jenkins):在升级版本中使用存档的工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆