Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aliasing jenkins artifact URLs

Tags:

jenkins

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

we 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 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 would then resolve to MyJob-v1.0.1.zip.

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

like image 759
paleozogt Avatar asked Apr 30 '14 17:04

paleozogt


People also ask

Where are Jenkins artifacts stored?

By default, Jenkins archives artifacts generated by the build. These artifacts are stored in the JENKINS_HOME directory with all other elements such as job configuration files.

How do I delete old artifacts in Jenkins?

The artifacts for a build by default are located in: [JENKINS_HOME]/jobs/[job_name]/builds/[$BUILD_ID]/archive/ , go there and delete it.

How do you publish artifacts in Jenkins pipeline?

Publish a package using JenkinsSelect your build pipeline, and then select Configure to edit your build definition. Select Build, and then select Add build step to add a new task. Select Save, and then queue your build. Your NuGet package should be published to your Azure Artifacts feed.


1 Answers

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

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)

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.

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

Edit:

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:

  • Get any possible [undetermined count] wildcard match and place into this container, then give me the container. This is logical and possible, as there is only one single container, whether it is empty or not.

But you cannot tell 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.

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.

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.

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

like image 110
Slav Avatar answered Oct 04 '22 12:10

Slav