jenkinsci / generic-webhook-trigger-plugin

Can receive any HTTP request, extract any values from JSON or XML and trigger a job with those values available as variables. Works with GitHub, GitLab, Bitbucket, Jira and many more.
https://plugins.jenkins.io/generic-webhook-trigger
404 stars 159 forks source link

Token automatically disappears #182

Closed zuanzuanshao closed 3 years ago

zuanzuanshao commented 3 years ago

When reporting a bug, please try to provide as much information as possible.

when i start a pipeline, then generic webhook token disappears, everytime i need manul to fill the token, Has anyone else been in this situation?

tomasbjerre commented 3 years ago

Supply your pipeline script.

zuanzuanshao commented 3 years ago

Supply your pipeline script.

pipeline { agent any triggers { GenericTrigger( genericVariables: [ [key: 'ref', value: '$.ref'], [key: 'project_name', value: '$.project.name'], [key: 'owner', value: '$.user_username'] ], causeString: 'Triggered on $ref', printContributedVariables: true, printPostContent: true, silentResponse: false, regexpFilterText: '$ref', ) } environment { project_name = "smaug-pvs" owner = 'zuanzuan.shao' } stages {

    stage('PreBuild') {
        agent any
        steps {
            echo 'start prebuild'
            echo "${WORKSPACE}"
            sh "find ./src -name '*.pyc' | xargs rm -f"
            sh "find ./src -name '*.pyo' | xargs rm -f"
        }
    }

    stage('Build') {
        agent {
            docker {
                image 'python:2.7.10'
            }
        }
        steps {
            echo "${WORKSPACE}"
            echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}"
            sh "python --version"
            sh "find ./src -name '*.py' | grep -v config.py | grep -v __init__.py | grep -v vars.py | xargs python -m py_compile"
        }
    }

    stage('Test') {
        agent {
            docker {
                image 'eloomi/unittest:v3'
            }
        }
        steps {
            echo "${WORKSPACE}"
            echo "start testing"
            sh "find ./src -name '*.py' | grep -v config.py | grep -v __init__.py | grep -v vars.py | xargs rm -f"
        }
    }

    stage('文件同步') {
        agent any
        steps {
            script {
                sh 'printenv'
                echo "开始文件同步"
                // 定义远程服务器
                def remote = [:]
                remote.name = 'test'
                remote.host = '10.0.86.78'
                remote.user = 'musibiis'
                remote.allowAnyHosts = true
                remote.identityFile = '/root/.ssh/id_rsa'
                // 传送源码到指定服务器
                writeFile file: 'send_source.sh', text: "mkdir -p /Users/musibiis/" + "${env.owner}" + "/" + "${env.project_name}" + "/dist"
                sshScript remote: remote, script: "send_source.sh"
                sshPut remote: remote, from: "${workspace}/", into: "/Users/musibiis/${env.owner}/${env.project_name}/dist/"

                // 将源码打包
                sh "tar --exclude '.git' -cvzf ${env.project_name}-source.tar.gz ${workspace}/*"
                echo "${env.project_name}"

                writeFile file: 'jemeter.sh', text: "mkdir -p /Users/musibiis/" + "${env.owner}" + "/" + "${env.project_name}" + "/"
                sshScript remote: remote, script: "jemeter.sh"
                echo "start ***************"
                stage('Remote SSH') {
                    sshCommand remote: remote, command: "mkdir -p /Users/musibiis/${env.owner}/${env.project_name}/"
                    sshPut remote: remote, from: "${env.project_name}-source.tar.gz", into: "/Users/musibiis/${env.owner}/${env.project_name}/"
                }
            }
        }
    }

}
   // post {
   //     success {
   //         mail to: "zuanzuan.shao@tophant.com", subject: "SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay, we passed."
   //     }
   //     failure {
   //         mail to: "zuanzuan.shao@tophant.com", subject: "FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed."
   //     }
   // }

}

this is my Jenkinsfile, with gitlab webhook do work.

tomasbjerre commented 3 years ago

You need to add the token to the GenericTrigger( part.

Den mån 21 sep. 2020 07:39musibii notifications@github.com skrev:

Supply your pipeline script.

pipeline { agent any triggers { GenericTrigger( genericVariables: [ [key: 'ref', value: '$.ref'], [key: 'project_name', value: '$.project.name'], [key: 'owner', value: '$.user_username'] ], causeString: 'Triggered on $ref', printContributedVariables: true, printPostContent: true, silentResponse: false, regexpFilterText: '$ref', ) } environment { project_name = "smaug-pvs" owner = 'zuanzuan.shao' } stages {

stage('PreBuild') {

    agent any

    steps {

        echo 'start prebuild'

        echo "${WORKSPACE}"

        sh "find ./src -name '*.pyc' | xargs rm -f"

        sh "find ./src -name '*.pyo' | xargs rm -f"

    }

}

stage('Build') {

    agent {

        docker {

            image 'python:2.7.10'

        }

    }

    steps {

        echo "${WORKSPACE}"

        echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}"

        sh "python --version"

        sh "find ./src -name '*.py' | grep -v config.py | grep -v __init__.py | grep -v vars.py | xargs python -m py_compile"

    }

}

stage('Test') {

    agent {

        docker {

            image 'eloomi/unittest:v3'

        }

    }

    steps {

        echo "${WORKSPACE}"

        echo "start testing"

        sh "find ./src -name '*.py' | grep -v config.py | grep -v __init__.py | grep -v vars.py | xargs rm -f"

    }

}

stage('文件同步') {

    agent any

    steps {

        script {

            sh 'printenv'

            echo "开始文件同步"

            // 定义远程服务器

            def remote = [:]

            remote.name = 'test'

            remote.host = '10.0.86.78'

            remote.user = 'musibiis'

            remote.allowAnyHosts = true

            remote.identityFile = '/root/.ssh/id_rsa'

            // 传送源码到指定服务器

            writeFile file: 'send_source.sh', text: "mkdir -p /Users/musibiis/" + "${env.owner}" + "/" + "${env.project_name}" + "/dist"

            sshScript remote: remote, script: "send_source.sh"

            sshPut remote: remote, from: "${workspace}/", into: "/Users/musibiis/${env.owner}/${env.project_name}/dist/"

            // 将源码打包

            sh "tar --exclude '.git' -cvzf ${env.project_name}-source.tar.gz ${workspace}/*"

            echo "${env.project_name}"

            writeFile file: 'jemeter.sh', text: "mkdir -p /Users/musibiis/" + "${env.owner}" + "/" + "${env.project_name}" + "/"

            sshScript remote: remote, script: "jemeter.sh"

            echo "start ***************"

            stage('Remote SSH') {

                sshCommand remote: remote, command: "mkdir -p /Users/musibiis/${env.owner}/${env.project_name}/"

                sshPut remote: remote, from: "${env.project_name}-source.tar.gz", into: "/Users/musibiis/${env.owner}/${env.project_name}/"

            }

        }

    }

}

}

// post {

// success {

// mail to: "zuanzuan.shao@tophant.com", subject: "SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay, we passed."

// }

// failure {

// mail to: "zuanzuan.shao@tophant.com", subject: "FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed."

// }

// }

}

this is my Jenkinsfile, with gitlab webhook do work.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jenkinsci/generic-webhook-trigger-plugin/issues/182#issuecomment-695909957, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADLKE3VNPITEYQDN7PKKCDSG3RHPANCNFSM4RUAXUDQ .

zuanzuanshao commented 3 years ago

You need to add the token to the GenericTrigger( part. Den mån 21 sep. 2020 07:39musibii notifications@github.com skrev: Supply your pipeline script. pipeline { agent any triggers { GenericTrigger( genericVariables: [ [key: 'ref', value: '$.ref'], [key: 'project_name', value: '$.project.name'], [key: 'owner', value: '$.user_username'] ], causeString: 'Triggered on $ref', printContributedVariables: true, printPostContent: true, silentResponse: false, regexpFilterText: '$ref', ) } environment { project_name = "smaug-pvs" owner = 'zuanzuan.shao' } stages { stage('PreBuild') { agent any steps { echo 'start prebuild' echo "${WORKSPACE}" sh "find ./src -name '.pyc' | xargs rm -f" sh "find ./src -name '.pyo' | xargs rm -f" } } stage('Build') { agent { docker { image 'python:2.7.10' } } steps { echo "${WORKSPACE}" echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}" sh "python --version" sh "find ./src -name '.py' | grep -v config.py | grep -v init.py | grep -v vars.py | xargs python -m py_compile" } } stage('Test') { agent { docker { image 'eloomi/unittest:v3' } } steps { echo "${WORKSPACE}" echo "start testing" sh "find ./src -name '.py' | grep -v config.py | grep -v init.py | grep -v vars.py | xargs rm -f" } } stage('文件同步') { agent any steps { script { sh 'printenv' echo "开始文件同步" // 定义远程服务器 def remote = [:] remote.name = 'test' remote.host = '10.0.86.78' remote.user = 'musibiis' remote.allowAnyHosts = true remote.identityFile = '/root/.ssh/id_rsa' // 传送源码到指定服务器 writeFile file: 'send_source.sh', text: "mkdir -p /Users/musibiis/" + "${env.owner}" + "/" + "${env.project_name}" + "/dist" sshScript remote: remote, script: "send_source.sh" sshPut remote: remote, from: "${workspace}/", into: "/Users/musibiis/${env.owner}/${env.project_name}/dist/" // 将源码打包 sh "tar --exclude '.git' -cvzf ${env.project_name}-source.tar.gz ${workspace}/*" echo "${env.project_name}" writeFile file: 'jemeter.sh', text: "mkdir -p /Users/musibiis/" + "${env.owner}" + "/" + "${env.project_name}" + "/" sshScript remote: remote, script: "jemeter.sh" echo "start *****" stage('Remote SSH') { sshCommand remote: remote, command: "mkdir -p /Users/musibiis/${env.owner}/${env.project_name}/" sshPut remote: remote, from: "${env.project_name}-source.tar.gz", into: "/Users/musibiis/${env.owner}/${env.project_name}/" } } } } } // post { // success { // mail to: *@.", subject: "SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay, we passed." // } // failure { // mail to: @.***", subject: "FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed." // } // } } this is my Jenkinsfile, with gitlab webhook do work. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#182 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADLKE3VNPITEYQDN7PKKCDSG3RHPANCNFSM4RUAXUDQ .

yep, thanks.

zuanzuanshao commented 3 years ago

You need to add the token to the GenericTrigger( part. Den mån 21 sep. 2020 07:39musibii notifications@github.com skrev: Supply your pipeline script. pipeline { agent any triggers { GenericTrigger( genericVariables: [ [key: 'ref', value: '$.ref'], [key: 'project_name', value: '$.project.name'], [key: 'owner', value: '$.user_username'] ], causeString: 'Triggered on $ref', printContributedVariables: true, printPostContent: true, silentResponse: false, regexpFilterText: '$ref', ) } environment { project_name = "smaug-pvs" owner = 'zuanzuan.shao' } stages { stage('PreBuild') { agent any steps { echo 'start prebuild' echo "${WORKSPACE}" sh "find ./src -name '.pyc' | xargs rm -f" sh "find ./src -name '.pyo' | xargs rm -f" } } stage('Build') { agent { docker { image 'python:2.7.10' } } steps { echo "${WORKSPACE}" echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}" sh "python --version" sh "find ./src -name '.py' | grep -v config.py | grep -v init.py | grep -v vars.py | xargs python -m py_compile" } } stage('Test') { agent { docker { image 'eloomi/unittest:v3' } } steps { echo "${WORKSPACE}" echo "start testing" sh "find ./src -name '.py' | grep -v config.py | grep -v init.py | grep -v vars.py | xargs rm -f" } } stage('文件同步') { agent any steps { script { sh 'printenv' echo "开始文件同步" // 定义远程服务器 def remote = [:] remote.name = 'test' remote.host = '10.0.86.78' remote.user = 'musibiis' remote.allowAnyHosts = true remote.identityFile = '/root/.ssh/id_rsa' // 传送源码到指定服务器 writeFile file: 'send_source.sh', text: "mkdir -p /Users/musibiis/" + "${env.owner}" + "/" + "${env.project_name}" + "/dist" sshScript remote: remote, script: "send_source.sh" sshPut remote: remote, from: "${workspace}/", into: "/Users/musibiis/${env.owner}/${env.project_name}/dist/" // 将源码打包 sh "tar --exclude '.git' -cvzf ${env.project_name}-source.tar.gz ${workspace}/*" echo "${env.project_name}" writeFile file: 'jemeter.sh', text: "mkdir -p /Users/musibiis/" + "${env.owner}" + "/" + "${env.project_name}" + "/" sshScript remote: remote, script: "jemeter.sh" echo "start *****" stage('Remote SSH') { sshCommand remote: remote, command: "mkdir -p /Users/musibiis/${env.owner}/${env.project_name}/" sshPut remote: remote, from: "${env.project_name}-source.tar.gz", into: "/Users/musibiis/${env.owner}/${env.project_name}/" } } } } } // post { // success { // mail to: *@.", subject: "SUCCESS: ${currentBuild.fullDisplayName}", body: "Yay, we passed." // } // failure { // mail to: @.***", subject: "FAILURE: ${currentBuild.fullDisplayName}", body: "Boo, we failed." // } // } } this is my Jenkinsfile, with gitlab webhook do work. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#182 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADLKE3VNPITEYQDN7PKKCDSG3RHPANCNFSM4RUAXUDQ .

There it comes again. I already put token to Jenkinsfile like below:

pipeline { agent any triggers { GenericTrigger( genericVariables: [ [key: 'ref', value: '$.ref'], [key: 'project_name', value: '$.project.name'], [key: 'owner', value: '$.user_username'] ], causeString: 'Triggered on $ref', printContributedVariables: true, printPostContent: true, silentResponse: false, regexpFilterText: '$ref', ) } } what can i do to solve this problem?

tomasbjerre commented 3 years ago

I do not see a token in that example. Here is an example with token: 'abc123',:

pipeline {
  agent any
  triggers {
    GenericTrigger(
     genericVariables: [
      [key: 'ref', value: '$.ref']
     ],

     causeString: 'Triggered on $ref',

     token: 'abc123',

     printContributedVariables: true,
     printPostContent: true,

     silentResponse: false,

     regexpFilterText: '$ref',
     regexpFilterExpression: 'refs/heads/' + BRANCH_NAME
    )
  }
  stages {
    stage('Some step') {
      steps {
        sh "echo $ref"
      }
    }
  }
}
zuanzuanshao commented 3 years ago

I do not see a token in that example. Here is an example with token: 'abc123',:

pipeline {
  agent any
  triggers {
    GenericTrigger(
     genericVariables: [
      [key: 'ref', value: '$.ref']
     ],

     causeString: 'Triggered on $ref',

     token: 'abc123',

     printContributedVariables: true,
     printPostContent: true,

     silentResponse: false,

     regexpFilterText: '$ref',
     regexpFilterExpression: 'refs/heads/' + BRANCH_NAME
    )
  }
  stages {
    stage('Some step') {
      steps {
        sh "echo $ref"
      }
    }
  }
}

I just find it, i put my git commit reset. Sorry...