How to access Hudson job1 artifacts from another job2?
Asked Answered
R

3

8

We have a production job and a nightly job for a project in Hudson. The production job needs to pull off some artifacts from a specific nightly build # (which is provided as parameter). Can anyone help us with a hint on how to achieve this?

Reprehensible answered 17/3, 2011 at 9:43 Comment(0)
F
8

The Copy Artifact plugin seems to be capable of doing this.

Another approach could be to fetch the artifact via

http://server/jobs/job1/[build #]/artifacts/
Foreignism answered 17/3, 2011 at 10:28 Comment(7)
We make extensive use of simple HTTP get against the job's download URL to pull artifacts into a downstream job.Anopheles
The problem with copy artifact plugin is that you need to know what artifacts you will need somewhere else. If we forget that and copy all artifacts by default, which are around 40-50 MB per build, this would increase disk usage at double speed. Fetching via URL is not possible because our setup requires authentication.Reprehensible
@Konstantin I'm guessing those URLs dont require authentication, right?Reprehensible
@Abhimayu: How about either fetching the artifact with a HTTP tool that supports authentication or disable authentication on the Jenkins server for requests from the local ip?Foreignism
"disable authentication on the Jenkins server for requests from the local ip" How is that possible? Hudson handles authentication itself (its not HTTP authentication), otherwise it would not have been a problem.Reprehensible
What are your settings for Security realm and Authorization?Foreignism
I've never used Matrix authentication, but wouldn't it be possible to give Anonymous access to Read jobs?Foreignism
M
1

You can use "Build Environment" configuration tools in the job's configuration page. Tick the Configure M2 Extra Build Steps box and add an Execute Shell which grep things from the desired artifact.

Municipality answered 21/3, 2011 at 11:34 Comment(0)
C
0

We have similar need and use the following system groovy:

import hudson.model.*

def currentBuild = Thread.currentThread().executable;
currentBuild.addAction(new ParametersAction(new StringParameterValue('LAST_BUILD_STATUS', 'FAILURE')));
def buildJob = Hudson.instance.getJob("ArtifactJobName");
def artifacts = buildJob.getLastBuild().getArtifacts();
if (buildJob.getLastBuild().getResult() == Result.SUCCESS && artifacts != null && artifacts.size() > 0) {
    currentBuild.addAction(new ParametersAction(new StringParameterValue('VARIABLE_NAME', artifacts[0].getFileName())));
    currentBuild.addAction(new ParametersAction(new StringParameterValue('LAST_BUILD_STATUS', 'SUCCESS')));
}

This creates a VARIABLE_NAME with the artifact name in it from ArtifactJobName, which we use since they are all stored in a specific folder. I am not sure what will happen if you have multiple artifacts, but it seems you could get them from the artifacts array.

You could use getLastSuccessfulBuild to prevent issue when another ArtifactJobName is being build at the moment and you get array with null.

Cornflakes answered 12/9, 2014 at 15:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.