Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: How can I know if an automatic process or a user has triggered a build?

Is there an environment variable in Jenkins which tells me if the build has been ran manually or automatically triggered by polling?

My pipeline works like a charm if automatically triggered, but if manually ran... it always fails, so I think I'm going to edit the pipeline to check how the build has been triggered.

like image 700
Itai Ganot Avatar asked Jun 19 '17 13:06

Itai Ganot


People also ask

Can Jenkins build be triggered automatically?

Follow the steps as mentioned below to trigger a Jenkins job automatically based on GitHub's webhook configurations: Step 1: Go to the Configuration page of the respective job and under the build trigger section, check the "GitHub hook trigger for GITScm polling" checkbox and click on the Save button.

Can you list few ways by which we can trigger a build in Jenkins?

Trigger builds remotely. Build after other projects are built. Build periodically. GitHub hook trigger for GITScm polling.

How can you automatically trigger a build when a developer check in code?

In Jenkins, go to the project configuration of the project for which you want to run an automated build. In the 'Build Triggers' section, select 'Build when a change is pushed to GitHub'. Save your project. Jenkins will now run the build when you push your code to the GitHub repository.

Can Jenkins build job be triggered manually?

Builds can be triggered by repository events, such as source code changes; triggered on a schedule; or triggered by post-processing events, such as completing builds in related projects.


1 Answers

Unfortunately variable env.BUILD_CAUSE is not set in Pipeline builds. For pipeline jobs see following example

if ( currentBuild.rawBuild.getCauses()[0].toString().contains('UserIdCause') ){
    // do steps for manual trigger here
}

Other possible causes to compare can be found here.

like image 140
Mohammad Azim Avatar answered Nov 03 '22 11:11

Mohammad Azim