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

2

12

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?

Malt answered 10/10, 2016 at 14:6 Comment(2)
You should use jenkins api to get this like http://$host/job/$jobname/lastSuccessfulBuild/api/json wiki.jenkins-ci.org/display/JENKINS/Remote+access+APIContumelious
I tried it already but it shows artifacts:[]Malt
M
11

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

Malt answered 13/10, 2016 at 12:7 Comment(1)
I'm getting an error here: java.lang.IllegalArgumentException: The parent does not existRiddick
F
2

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>
Fester answered 10/10, 2016 at 14:27 Comment(3)
Thanks, do you happen to have reference about archiving the artifacts? I couldn't find an elaborated one...Malt
I added part of the job config. We're not using the pipeline yet, so I cannot help you on the specifics.Fester
github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md --> Recording Test Results and ArtifactsLemuroid

© 2022 - 2024 — McMap. All rights reserved.