embedded_crysis
embedded_crysis

Reputation: 213

Trigger Jenkins pipeline from Gitlab webhook

Just started with Jenkins and I can't seem to get how to properly configure SCM for pipelines since there's no SCM config tab there. I've added a webhook to my gitlab project, with URL

http://my-jenkins-server.com/git/notifyCommit?url=https://my-gitlab-server.com/my-repo.git

But when I visit that URL, Jenkins tells me

No Git consumers using SCM API plugin for: https://my-gitlab-server.com/my-repo.git

which sort of makes sense because I haven't explicitly told Jenkins that my pipeline is tied to this repo, just implicitly in the Jenkins script:

stage('Build'){
    git url: 'https://my-gitlab-server.com/my-repo.git', branch: 'master', credentialsId: '<some-hash>'
    sh 'cd linux-native; make clean all'
}

So how do I tell Jenkins that a PIPELINE is tied to a specific repo? Alternatively, how do I find the proper notifyCommit url for my pipeline?

Upvotes: 2

Views: 6530

Answers (2)

Abdull
Abdull

Reputation: 27862

I had to explicitly uncheck "Lightweight checkout" (under "Pipeline") for the first git checkout to work correctly and the pipeline to start.

Upvotes: 0

Christopher Orr
Christopher Orr

Reputation: 111625

Assuming that you've enabled the Poll SCM option, Git webhooks should function as they do for Freestyle jobs.

But you will need to run the Pipeline manually at least once before /git/notifyCommit hooks will work.

For Freestyle projects, Jenkins can fairly easily inspect the job config and see which SCM is configured. For Scripted Pipeline, Jenkins can't determine what SCM you're using (if any) until it actually executes the Pipeline.

Upvotes: 3

Related Questions