别名詹金斯工件URL [英] aliasing jenkins artifact URLs

查看:111
本文介绍了别名詹金斯工件URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins工件URL允许抽象上一次成功构建",因此代替了

Jenkins artifact URLs allow abstracting the "last successful build", so that instead of

http://myjenkins.local/job/MyJob/38/artifact/build/MyJob-v1.0.1.zip

我们可以说

http://myjenkins.local/job/MyJob/lastSuccessfulBuild/artifact/build/MyJob-v1.0.1.zip

是否可以进一步对此进行抽象?我的工件的文件名中包含其版本号,该版本号可以随版本的不同而变化.理想情况下,我想使用某种别名" URL,如下所示:

Is it possible to abstract this further? My artifacts have their version number in their filename, which can change from build to build. Ideally I'd like to have a some kind of "alias" URL that looks like this:

http://myjenkins.local/job/MyJob/lastSuccessfulBuild/artifact/build/MyJob-latest.zip

MyJob-latest.zip然后将解析为MyJob-v1.0.1.zip.

如果詹金斯(Jenkins)本身无法做到这一点,那么也许有一个插件?

If Jenkins itself can't do this, perhaps there's a plugin?

推荐答案

从未见过这样的插件,但是Jenkins已经内置了类似的功能.

Never seen any such plugin, but Jenkins already has a similar functionality built-in.

您可以在工件路径中使用/*zip*/filename.zip,其中filename是您选择的任何内容.它将带走所有找到的工件,并将它们下载到一个zip文件中(如果您的工件已经是一个zip文件,则最终可能会在zip文件中找到一个zip文件)

You can use /*zip*/filename.zip in your artifact path, where filename is anything you choose. It will take all found artifacts, and download them in a zipfile (you may end up with a zip inside a zip, if your artifact is already a zip file)

在您的情况下,它将是:
http://myjenkins.local/job/MyJob/lastSuccessfulBuild/artifact/build/*zip*/MyJob-latest.zip
这将使您获得名为MyJob-latest.zip的压缩存档中返回的/artifact/build/的内容.请注意,如果该目录中不仅有该zip文件,还将返回其他文件.

In your case, it will be:
http://myjenkins.local/job/MyJob/lastSuccessfulBuild/artifact/build/*zip*/MyJob-latest.zip
This will get you the contents of /artifact/build/ returned in zipped archive with name MyJob-latest.zip. Note that if you have more than just that zip file in that directory, other files will be returned too.

您可以在路径中使用通配符.单个*用于常规通配符,双**用于跳过任何数量的先前目录.

You can use wildcards in the path. A single * for a regular wildcard, a double ** for skipping any number of preceding directories.

例如,要获取以MyJob开头,以.zip结尾的任何文件,并在任何工件目录中查找它,可以使用:

For example, to get any file that starts with MyJob, ends with .zip, and to look for it in any artifact directory, you could use:

/lastSuccessfulBuild/artifact/**/MyJob*.zip/*zip*/MyJob-latest.zip

如果没有 some 形式的容器(在这种情况下为zip),您将无法执行此类操作.使用该容器,您将告诉系统:

You cannot do something like this without some form of a container (a zip in this case). With the container, you are telling the system:

  • 获取任何可能的[不确定的数量]通配符匹配并将其放入此容器,然后再给我该容器.这是合乎逻辑的,也是可能的,因为只有一个容器(无论是否为空).

但是您不能告诉系统:

  • 给我一个指向特定单个文件的链接,但我不知道有哪个文件或多少个文件.系统无法保证您的通配符将匹配一个,多个或不匹配.从逻辑的角度来看,这根本是不可能的.
  • Give me a link to a specific single file, but I don't know which one or how many there are. The system can't guarantee that your wildcards will match one, more than one, or none. This is simply impossible from a logic perspective.

如果您需要它来实现某些脚本自动化,则可以解压缩第一级zip,并保留所需的压缩工件.

If you need it for some script automation, you can unzip the first level zip and be still left with your desired zipped artifact.

如果您需要将此链接提供给其他人,则需要替代解决方案.

If you need to provide this link to someone else, you need an alternative solution.

替代1:
构建完成后,执行一个构建后步骤,该步骤将使用您的工件,并将其重命名为MyJob-latest.zip,但是您将丢失文件名中的版本控制.您还可以选择复制而不是重命名,但是最终会导致存储这些工件的空间增加一倍.

Alternative 1:
After your build is complete, execute a post-build step that will take your artifact, and rename it to MyJob-latest.zip, but you are losing versioning in the filename. You can also chose to copy instead of rename, but you end up with double the space used for storing these artifacts.

替代2(推荐): 作为构建后的操作,请将工件上载到中央存储库.它可以是Artifactory,甚至是普通的SVN.上载时,它将重命名为MyJob-latest.zip,而上一个将被覆盖.这样,您就有了一个静态链接,该链接将始终具有lastSuccessfulBuild

Alternative 2 (recommended): As a post-build action, upload the artifact to a central repository. It can be Artifactory, or even plain SVN. When you upload it, it will be renamed MyJob-latest.zip and the previous one would be overwritten. This way you have a static link that will always have the latest artifact from lastSuccessfulBuild

这篇关于别名詹金斯工件URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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