Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins simple pipeline not triggered by github push

enter image description hereI have created a jenkins pipeline job called "pipelinejob" with the below script:

pipeline {
    agent any

    stages {

        stage ('Setup'){
            steps{
                //echo "${BRANCH_NAME}"
                echo "${env.BRANCH_NAME}"
                //echo "${GIT_BRANCH}"
                echo "${env.GIT_BRANCH}"
            }
        }
    }
}

1) Under General, I have selected "GitHub project" and inserted my company's github in the form:

https://github.mycompany.com/MYPROJECTNAME/MY_REPOSITORY_NAME/

2) Under Build Triggers, i have checked "GitHub hook trigger for GITScm polling

3) I have created a simple job called "simplejob" with same configuration as 1) and 2)

4) In my company's Github, i have created a webhook like "jenkins_url/jenkins/github-webhook/"

5) I commit a change in "mybranch" in "MY_REPOSITORY_NAME"

6) My simple job "simplejob" is triggered and built successfully

7) My pipeline job "pipelinejob" is not triggered

8) In Jenkins log i see the below:

Sep 12, 2019 2:42:45 PM INFO org.jenkinsci.plugins.github.webhook.subscriber.DefaultPushGHEventSubscriber$1 run
Poked simplejob

Nothing regarding my "pipelinejob".

Could you please point me to the right directions as to what to check next?

P.S. I have manually executed my "pipelinejob" successfully

like image 230
Dim Malt Avatar asked Sep 12 '19 15:09

Dim Malt


People also ask

How do I trigger Jenkins job in Git push?

Go to Manage Jenkins -> Global Tool Configuration -> Git Add git executable path to Global Tool Configuration. Let us start with creating a Freestyle Project : Step 1: Go to New Item -> create a freestyle project. Step 2: Go to Configure, add a project description, and Github project URL.

How to trigger GitHub push event in Jenkins pipeline?

We need to declare the Github push event trigger in Jenkins file as follows. The declaration should be in the first line. git url: The URL on which pipeline should be triggered. branch: The branch on which pipeline should be triggered.

Why is my Poll not running in Jenkins pipeline?

If it says 'Polling has not run yet', you will need to manually trigger the pipeline job once before Jenkins registers it to poke on receiving hooks. Henceforth, the job should automatically trigger on GitHub push events.

How to create a pipeline job for Git push using GitHub-webhook?

The thing is whenever you create a pipeline job for git push which is to be triggered by github-webhook, first you need to build the pipeline job manually for one time. If it builds successfully, then Jenkins registers it to poke on receiving hooks. And from the next git push, your pipeline job will trigger automatically.

When does Jenkins register a pipeline job to poke?

If it builds successfully, then Jenkins registers it to poke on receiving hooks. And from the next git push, your pipeline job will trigger automatically. Note: Also make sure that the pipeline job built manually for the first time should be built successfully, otherwise Jenkins will not poke it.


Video Answer


3 Answers

I wasted two days of work on this, as none of the previous solutions worked for me. :-(
Eventually I found the solution on another forum:
The problem is that if you use a Jenkinsfile that is stored in GitHub, along with your project sources, then this trigger must be configured in the Jenkinsfile itself, not in the Jenkins or project configuration.
So add a triggers {} block like this to your Jenkinsfile:

pipeline {
  agent any
  triggers {
    githubPush()
  }
  stages {
...
  }
}

Then...

  • Push your Jenkinsfile into GitHub
  • Run one build manually, to let Jenkins know about your will to use this trigger.
    You'll notice that the "GitHub hook trigger for GITScm polling" checkbox will be checked at last!
  • Restart Jenkins.

The next push should trigger an automated build at last!

like image 60
Jean-François Larvoire Avatar answered Oct 18 '22 22:10

Jean-François Larvoire


I found an answer to this question with scripted pipeline file. We need to declare the Github push event trigger in Jenkins file as follows.

properties([pipelineTriggers([githubPush()])])

node {
        git url: 'https://github.com/sebin-vincent/Treasure_Hunt.git',branch: 'master'
        stage ('Compile Stage') {

            echo "compiling"
            echo "compilation completed"
        }

        stage ('Testing Stage') {

            echo "testing completed"
            echo "testing completed"
        }
        stage("Deploy") {

                echo "deployment completed"
                        }
            }
}

The declaration should be in the first line.

git url: The URL on which pipeline should be triggered.

branch: The branch on which pipeline should be triggered. When you specify the branch as master and make changes to other branches like develop or QA, that won't trigger the pipeline.

Hope this could help someone who comes here for an answer for the same problem with Jenkins scripted pipeline :-(.

like image 29
sebin vincent Avatar answered Oct 18 '22 21:10

sebin vincent


On the left side-pane of your pipeline job, click GitHub Hook log. If it says 'Polling has not run yet', you will need to manually trigger the pipeline job once before Jenkins registers it to poke on receiving hooks.

Henceforth, the job should automatically trigger on GitHub push events.

like image 5
Dibakar Aditya Avatar answered Oct 18 '22 20:10

Dibakar Aditya