简体   繁体   中英

Webhook| Gitlab | jenkins pipeline |Declarative syntax

I'm trying to integrate Webhook with gitlab and jenkins. I have done it via upstream downstream jobs using the URL. While trying to rece=reate the same via declarative pipeline, I'm in a stanstill

 pipeline {
  agent any
  stages {
    stage('fetchcodeFromGit') {
      steps {
        timeout(time: 30) {
          git(url: 'http:<<>>/JenkinsPipeline.git', branch: 'master', credentialsId: 'QualityAssurance', poll: true)
        }

      }
    }

Can anyone help with documents or any sample snippets?

If you choose pipeline script instead declarative pipeline, this post could be help you :

https://jrichardsz.github.io/devops/devops-with-git-and-jenkins-using-webhooks

Steps:

  • Configure required plugins in jenkins.
  • Jenkins user and password.
  • Create a jenkins job which will be triggered by your git provider. This job publish an http url ready to use. We will call webhook_url to this url.
  • Configure webhook_url in webhook section of your git provider of some repository.
  • Test this flow, pushing some change to your git repository or simulating it using comandline.

You can use this snippet:

pipeline {

options {
    gitLabConnection('your-gitlab-conn')
}

triggers {
    gitlab(
      triggerOnPush: false,
      triggerOnMergeRequest: true, triggerOpenMergeRequestOnPush: "both",
      triggerOnNoteRequest: true,
      noteRegex: "Jenkins please retry a build",
      skipWorkInProgressMergeRequest: false,
      ciSkip: false,
      setBuildDescription: true,
      addNoteOnMergeRequest: true,
      addCiMessage: true,
      addVoteOnMergeRequest: true,
      acceptMergeRequestOnSuccess: false,
      branchFilterType: "All",
      secretToken: "NOTVERYSECRET")
}

stages {
    ...

more details here: https://github.com/jenkinsci/gitlab-plugin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM