4

I'm using Jenkins.

Jenkins has a upstream job : A
Jenkins has a downstream job : B

A's console log output is:

1
2
3

B's console log output is:

A
B
C

What I'm trying to get is:

IS there any way, I can get the console output of job B in Job A's console log and THEN, make a decision whether the JOB "A" was successful or not (using log parsing/grep a keyword for failuer/errors etc).

AKS
  • 16,482
  • 43
  • 166
  • 258
  • I have been looking for the same answer and haven't found one. – Nam Nguyen Mar 11 '15 at 20:01
  • I was thinking of using this plugin https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin to copy artifact file from downstream to upstream. I don't know if plugin will be able to solve the problem or not. – Nam Nguyen Mar 11 '15 at 20:04
  • 2
    The question's title doesn't match its description: _getting the console output from downstream to upstream_ vs. _setting upstream's build result depending on downstream_. If it is the question's title you're interested in see [my answer](http://stackoverflow.com/a/31573477/1744774) to [Output the console text of a Jenkins job that my Job is running](http://stackoverflow.com/questions/31521030/output-the-console-text-of-a-jenkins-job-that-my-job-is-running). – Gerold Broser Aug 02 '15 at 16:45

3 Answers3

2

Not sure what you are trying to achieve, but it looks rather contrived. See if the following approach fits your needs: start Job B from Job A via Parameterized Trigger Plugin as a build step. There is an option for A to wait for B and then adjust build result for A depending on that of B.

malenkiy_scot
  • 16,415
  • 6
  • 64
  • 87
  • If I select that option for A to wait, and if B fails, then do I need to do any log checking to find an error or will it automatically mark the job A failed if B fails (by any means). – AKS Jul 11 '12 at 21:36
  • It will automatically mark A as failed if you select the appropriate option. – malenkiy_scot Jul 11 '12 at 21:39
0

One quick and easy way is to just use curl

i.e.

curl http://myJenkinsServer:9090/job/ProjectNamel/$childJobLastBuildNumber/consoleFull  | sed "s#<span class="timestamp"><b>##g;s#</b> </span># #g" 

... where $childJobLastBuildNumber is the latest / last build# of the child/downstream job.

Using curl and sed - now I can show the output of child/downstream job in parent job if I run the above curl | sed .. command in Execute Shell.

AKS
  • 16,482
  • 43
  • 166
  • 258
  • What is the easiest way to assign the correct value to `$childJobLastBuildNUmber` – ThisGuyCantEven Mar 25 '19 at 15:02
  • Job A --> call Job B. Job B, will create a file (ex: properties.txt) in Job A's workspace (which you can pass to Job B as a parameter) and inserts a key=value pair in it (ex: JOB_B_BUILD_NUMBER=$BUILD_NUMBER) i.e. now Job A's workspace will have this properties.txt file containing the above variable=value. When Job B completes and control comes back to Job A, you can use $JOB_B_BUILD_NUMBER in place of $childJobLastBuildNumber or set this variable to the value of JOB_B_BUILD_NUMBER and use curl. There are also other easy way like, just `cat path/jobBFullConsoleOutput` in Job A's build section. – AKS Mar 25 '19 at 16:06
0

To get the console output of job B.

I haven't found a better approach than displaying the job log file with cat. You'll have to make the "job B trigger" step as a block. So that job A won't finish until job B does. Then after the "job B trigger" step, add a step to execute a shell script.

cat "$JENKINS_HOME/jobs/<PATH_TO_YOUR_JOB>/builds/$TRIGGERED_BUILD_NUMBER_<FOLDER_AND_JOB_NAME>/log"

Note that $TRIGGERED_BUILD_NUMBER_<FOLDER_AND_JOB_NAME> is an environment variable injected by Jenkins dynamically.

To decide whether job A fails or not based on job B.

You don't have to parse the downstream job's console output. In the upstream job's configuration, when triggering job B, you have the options to choose from. Like:

  • Fail this build step if the triggered build is worse or equal to
  • Mark this build as failure if the triggered build is worse or equal to
  • Mark this build as unstable if the triggered build is worse or equal to
Liwei Fu
  • 3
  • 2