问题描述:

When I trigger a job remotely using the API the job on jenkins say: "Started by remote host IP". But my jobs can trigger for different reasons and from different sources so it would be great if I in Jenkins could look at a job and directly see the trigger reason.

I know I could pass a string parameter and then in each job view the parameters - but that's not very visible. I would like to preferably see it already in the list of all jobs. Something like: Reason: X Source: N.

Is there any way to do this ?

I have noticed that our release jobs take a version parameter that shows like I want - but I don't want to abuse that since these runs are not releases.

网友答案:

Build Name

I think you want to set the build name to a different one like here:

So you can use the Build Name Setter Plugin and use the build step Update build name.

For your case you can use:

#${BUILD_NUMBER} ${BUILD_CAUSE}

Cause Badge

Have a look on Build Trigger Badge Plugin, it represents with an icon the reason of the build.

Extract the job cause

One possibility to extract the job cause is to use groovy, currentBuild is injected into the runtime and includes information about the causes and so on.

This prints the first (!) cause:

println ("Cause: " + currentBuild.causes[0])
网友答案:

Unfortunately, even with the Build Trigger Badge Plugin activated http://<Your Jenkins>/job/<Your job's name>/api/xml doesn't show the trigger cause.

You could parse the job's HTML for:

<div class="middle-align build-badge" style="width: 100%;">
  <img width="16" height="16" src="/plugin/buildtriggerbadge/images/user-cause.png"
    alt="Trigger UserIdCause : Started by user YourUser" title="Started by user YourUser">
</div>

See also the EnvInject Plugin:

This plugin also exposes the cause of the current build as an environment variable.

相关阅读:
Top