Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access artifacts created by Jenkins in the lastSuccessfulBuild through a URL?

I'm building an Android application using Jenkins pipeline.

When a build finishes successfully, it creates an .apk file.

I want members of the QA team to be able to download this file and test the application before uploading it Google store and so I want these users (which have access to the Jenkins server) to be able to access the artifact through a URL on the Jenkins server as shown in this SO question but for some reason the URL I'm using to try and download the artifact keeps giving me 404 error.

These are the links I'm trying to access but to no avail:

https://company-ci-server.company.net/job/Itai_repos/job/Product-Android/job/develop/lastSuccessfulBuild/build/outputs/apk/Company-production-release.apk

https://company-ci-server.company.net/job/Itai_repos/job/Product-Android/job/develop/lastSuccessfulBuild/artifact/product-production-release.apk

The job is configured as multi-branch which means that Jenkins is watching the project in GitHub, indexes all the branches and whenever a commit happens a job is starting... that is why the link is so long incase you wondered...

So what am I doing wrong? Why can't I access the artifacts through a URL?

like image 438
Itai Ganot Avatar asked Oct 10 '16 14:10

Itai Ganot


People also ask

Where can I see artifacts in Jenkins?

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 find my Jenkins API URL?

In the bottom right of each page Jenkins has a link to their REST API. This link will appear on every page of Jenkins and points you to an API output for the exact page you are browsing. That should provide some understanding about how to build the API URLs.

What is Jenkins job URL?

For a locally hosted Jenkins server, the URL would be: http://localhost:8080/env-vars.html. The easiest way to see how these Jenkins environment variables work is to create a freestyle job, echo each entry in the list and see the value Jenkins assigns to each property.


2 Answers

As post-build step in your build process Add a task "Archive the artifacts". And specify the files to be made accessible.

On you project dashboard page you will see a link to "Last successful artifacts"

Edit: part of our config added:

<hudson.tasks.ArtifactArchiver>
    <artifacts>
       bin\file1Setup.exe, bin\file2Setup.exe
    </artifacts>
    <allowEmptyArchive>false</allowEmptyArchive>
    <onlyIfSuccessful>false</onlyIfSuccessful>
    <fingerprint>false</fingerprint>
    <defaultExcludes>true</defaultExcludes>
</hudson.tasks.ArtifactArchiver>
like image 22
ReneA Avatar answered Sep 18 '22 14:09

ReneA


If it interests anyone, because I'm writing the pipeline myself and I'm not using the GUI to configure my job then I was missing the part of the actual archiving in the pipeline, here's the relevant missing code:

step([$class: 'ArtifactArchiver', artifacts: '**/build/outputs/apk/*.apk', fingerprint: false])

This step tells Jenkins to look for apk files in the given path. Then Jenkins publishes the apk and you can access it through URL:

https://ci-server.company.net/job/Itai_repos/job/Products-Android/job/develop/<BUILD_NUMBER>/artifact/

Thanks

like image 51
Itai Ganot Avatar answered Sep 19 '22 14:09

Itai Ganot