Jenkins aliases artifact urls

Jenkins artifact urls allow you to abstract away from the "last successful build", so instead

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

can say

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

Is it possible to abstract this further? My artifacts have their version number in the file name, which can vary from assembly to assembly. Ideally, I would like to have some kind of "alias" URL that looks like this:

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

MyJob-latest.zip will then be resolved by MyJob-v1.0.1.zip .

If Jenkins himself cannot do this, is there perhaps a plugin?

+6
source share
2 answers

I have never seen such a plugin, but Jenkins already has similar functionality.

You can use /*zip*/filename.zip in your path to the artifact, where filename is all you choose. It will take all the artifacts found and upload them to the zipfile (you can get the zip inside the zip if your artifact is already a zip file)

In your case, it will be:
http://myjenkins.local/job/MyJob/lastSuccessfulBuild/artifact/build/*zip*/MyJob-latest.zip
This will give you the contents of /artifact/build/ returned in the zipped archive named MyJob-latest.zip . Please note: if not only this zip file is in this directory, other files will also be returned.

You can use wildcards in the path. One * for a regular wildcard - double ** to skip any number of previous directories.

For example, to get any file starting with MyJob ends in .zip , and to search for it in any artifact directory, you can use:

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

Edit:

You cannot do something like this without any form of container (in this case, zip). With the container, you tell the system:

  • Get any possible (indefinite amount) wildcard match and put it in this container, and then give me the container. This is logical and possible, since there is only one container, empty or not.

But you cannot tell the system:

  • Give a link to a specific separate file, but I do not know which one or how many there are. The system cannot guarantee that your wildcards will match one, more than one, or no one. This is simply not possible from a logical point of view.

If you need this for some automation script, you can unzip the first level zip code and stay with your desired zip artifact.

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

Alternative 1:
After the assembly is completed, follow the assembly step that takes your artifact and rename it to MyJob-latest.zip , but you will lose version control in the file name. You can also copy instead of renaming, but in the end you double the space used to store these artifacts.

Alternative 2 (recommended): As an action after assembly, upload the artifact to the central repository. It could be Artifactory or even a simple SVN. When you download it, it will be renamed MyJob-latest.zip , and the previous one will be overwritten. So you have a static link that will always have the last artifact from lastSuccessfulBuild

+12
source

Actually there is a plugin for assigning aliases that you created, and I found it quite convenient: Set build alias plugin .

You can use it, for example, to assign an alias in the form of your own version number for the assembly instead of (or rather, additionally) the internal assembly number assigned by Jenkins. I found that it is usually most appropriate to use it in combination with the EnvInject plugin (or your favorite option): you export the env variable (e.g. MY_VAR = xyz) with the value to the target version or nickname, and then use the form ${ENV,var="myvar"} in the "Token Macro Attribute" configuration that the plugin provides in your job configuration.

You can also use it to assign aliases in the form "lastSuccesful" if you have a need that allows you to distinguish between different types of successful (or other states).

Wait more! You can also use the trick /*zip*/ in conjunction with the alias installer.

0
source

All Articles