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?
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.
The artifacts for a build by default are located in: [JENKINS_HOME]/jobs/[job_name]/builds/[$BUILD_ID]/archive/ , go there and delete it.
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.
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:
But you cannot tell the system:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With