jenkins安装Generic Webhook Trigger插件

然后配置如下
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
最后送上pipeline完整脚本


pipeline {
   agent any

options{  timestamps () }

  triggers {
        GenericTrigger(
            genericVariables: [
              [key: 'ref', value: '$.ref']
            ],
            
            token: 'jsj',
            //causeString: ' Triggered on $ref',
            //regexpFilterText: '$ref',
            printContributedVariables: true,
            printPostContent: true                    
        )
    }

   stages {
      stage('syntax-check') {
         steps {
             
        ansiblePlaybook (
        //inventory: '${hos}',
        colorized: true,
        playbook: '${book}',
        limit: '10.22.8.33,10.22.32.2',
        extras: '--syntax-check'
        )
       
         }
      }

      stage('Deloy') {
         steps {
             
        ansiblePlaybook (
        //inventory: '${hos}',
        playbook: '${book}',
        limit: '10.22.1.33,10.22.1.2',
        
        )
       
         }
      }
      
         stage('GWT') {
            steps {
                sh '''
                echo $ref
                printenv
                '''
            }
        }
      
   }
}

远程触发方式

请求参数: curl -vs http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=jsj 2>&1
令牌头: curl -vs -H "token: jsj" http://localhost:8080/jenkins/generic-webhook-trigger/invoke 2>&1
类型Bearer的授权标头:curl -vs -H "Authorization: Bearer jsj" http://localhost:8080/jenkins/generic-webhook-trigger/invoke 2>&1

在这里插入图片描述
PS:
添加参数"Content-Type:application/json会得到触发日志

curl -X POST -H "Content-Type:application/json" -d '{"ref":refs/heads/master" }' -vs http://10.22.1.34:8080/generic-webhook-trigger/invoke?token=jsj

如下

GenericWebhookEnvironmentContributor
 Received:

{"ref":refs/heads/master" }


Contributing variables:

    ref = refs/heads/master"

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐