Comments (11)
Keep the key as it was, but change the others.
from generic-webhook-trigger-plugin.
@tomasbjerre as per your recommendation I kept the key as it is and changed the other parameters to _0
and it started working as expected. Now its able to build only the TAG
based push. Here is the final code:
def val = "Jenkins-Agent-01"
def registryLogin = "docker-hub.example.com"
def imageURL = "centos/devops-build:latest"
pipeline {
agent {
node {
label val
customWorkspace "/opt/devops/workspace/${JOB_NAME}/${BUILD_NUMBER}"
}
}
triggers {
GenericTrigger(
genericVariables: [
[key: 'eventKey', value: '$.eventKey', defaultValue: 'null'],
[key: 'tagId', value: '$.changes[0].refId', defaultValue: 'null'],
[key: 'repoName', value: '$.repository.name', defaultValue: 'null'],
[key: 'repository_slug', value: '$.repository.slug', defaultValue: 'null'],
[key: 'repository_project_key', value: '$.repository.project.key', defaultValue: 'null'],
[key: 'changes_ref_ids', value: '$.changes[?(@.ref.type == "TAG")].ref.id', defaultValue: 'null']
],
causeString: 'Triggered By BitBucket',
token: '',
tokenCredentialId: '',
printContributedVariables: false,
printPostContent: false,
silentResponse: false,
regexpFilterText: '$changes_ref_ids_0',
regexpFilterExpression: '^refs/tags/.*$'
)
}
stages {
stage('Display Payload') {
steps {
script {
sh """
echo "Repo ref Id: ${changes_ref_ids_0)}"
echo "Repo Project Key: ${repository_project_key}"
"""
}
}
}
stage('Build Jar file') {
steps {
script {
docker.withRegistry("https://${registryLogin}", "docker-hub-creds") {
docker.image("${imageURL}").pull()
docker.image("${imageURL}").inside() {
echo "Starting the build...."
checkout([$class: 'GitSCM',
branches: [[name: "${tagId}"]],
userRemoteConfigs: [[credentialsId: "bitbucket-creds", url: "https://bitbucket.example.com/scm/${repository_project_key}/${repoName}.git"]]])
sh """
mvn help:evaluate -Dexpression=project.version -q -DforceStdout;
mvn clean install -DskipTests -Ptest
"""
}
}
}
}
}
}
}
As its working now, I am closing this issue. Thanks a lot for all the help.
from generic-webhook-trigger-plugin.
You need to supply the webhook being sent to the plugin. Without it, I cannot investigate this.
from generic-webhook-trigger-plugin.
You need to supply the webhook being sent to the plugin. Without it, I cannot investigate this.
I am using http://jenkins.example.com:8080/generic-webhook-trigger/invoke as the webhook URL and the payload is looking something like the below one:
{
"eventKey": "repo:refs_changed",
"date": "2023-06-26T08:48:28-0700",
"actor": {
"name": "Udayendu.Kar",
"emailAddress": "[email protected]",
"id": 5212,
"displayName": "Udayendu Kar",
"active": true,
"slug": "udayendu.kar",
"type": "NORMAL",
"links": {
"self": [
{
"href": "https://bitbucket.example.com/users/udayendu.kar"
}
]
}
},
"repository": {
"slug": "userdata-commons-demo",
"id": 1377,
"name": "userdata-commons-demo",
"hierarchyId": "2de66323486a8e2f3eb6",
"scmId": "git",
"state": "AVAILABLE",
"statusMessage": "Available",
"forkable": true,
"project": {
"key": "DEV",
"id": 381,
"name": "DevOps",
"public": false,
"type": "NORMAL",
"links": {
"self": [
{
"href": "https://bitbucket.example.com/projects/DEV"
}
]
}
},
"public": false,
"links": {
"clone": [
{
"href": "https://bitbucket.example.com/scm/dev/userdata-commons-demo.git",
"name": "http"
},
{
"href": "ssh://[email protected]:9981/dev/userdata-commons-demo.git",
"name": "ssh"
}
],
"self": [
{
"href": "https://bitbucket.example.com/projects/DEV/repos/userdata-commons-demo/browse"
}
]
}
},
"changes": [
{
"ref": {
"id": "refs/tags/v0.1.3",
"displayId": "v0.1.3",
"type": "TAG"
},
"refId": "refs/tags/v0.1.3",
"fromHash": "244dbecf09562ee842b69fdefbbafe82455a80b8",
"toHash": "0000000000000000000000000000000000000000",
"type": "ADD"
}
]
}
from generic-webhook-trigger-plugin.
Can you also supply a branch payload that should not trigger build?
from generic-webhook-trigger-plugin.
bitbucket.example.com
Please find the payload for the BRANCH based push:
{
"eventKey": "repo:refs_changed",
"date": "2023-06-27T03:52:50-0700",
"actor": {
"name": "Udayendu.Kar",
"emailAddress": "[email protected]",
"id": 5212,
"displayName": "Udayendu Sekhar Kar",
"active": true,
"slug": "udayendu.kar",
"type": "NORMAL",
"links": {
"self": [
{
"href": "https://bitbucket.example.com/users/udayendu.kar"
}
]
}
},
"repository": {
"slug": "userdata-commons-demo",
"id": 1377,
"name": "userdata-commons-demo",
"hierarchyId": "2de66323486a8e2f3eb6",
"scmId": "git",
"state": "AVAILABLE",
"statusMessage": "Available",
"forkable": true,
"project": {
"key": "DEV",
"id": 381,
"name": "DevOps",
"public": false,
"type": "NORMAL",
"links": {
"self": [
{
"href": "https://bitbucket.example.com/projects/DEV"
}
]
}
},
"public": false,
"links": {
"clone": [
{
"href": "https://bitbucket.example.com/scm/dev/userdata-commons-demo.git",
"name": "http"
},
{
"href": "ssh://[email protected]:9981/dev/userdata-commons-demo.git",
"name": "ssh"
}
],
"self": [
{
"href": "https://bitbucket.example.com/projects/DEV/repos/userdata-commons-demo/browse"
}
]
}
},
"changes": [
{
"ref": {
"id": "refs/heads/master",
"displayId": "master",
"type": "BRANCH"
},
"refId": "refs/heads/master",
"fromHash": "5047a4a2903e0ffcde92fce6652cdc49a707b3ec",
"toHash": "193dad002f045f1356053f46e4f0193ec167df11",
"type": "UPDATE"
}
]
}
from generic-webhook-trigger-plugin.
Can you also supply a branch payload that should not trigger build?
Just FYI, I am expecting a BRANCH payload should not trigger the build but its triggering as of now. So both TAG and BRANCH based code push are triggering the build for now and I just want the TAG based push should trigger the build.
from generic-webhook-trigger-plugin.
What is printed here for the branch event?
echo "Repo ref Id: ${changes_ref_ids}"
from generic-webhook-trigger-plugin.
What is printed here for the branch event? echo "Repo ref Id: ${changes_ref_ids}"
Nothing. It looks like below one:
Repo ref Id: []
from generic-webhook-trigger-plugin.
I tried it. I needed to change changes_ref_ids
to changes_ref_ids_0
but other than that it works on my machine!
Perhaps if you set these to true
:
printContributedVariables: true,
printPostContent: true,
It might give a hint of what is going on.
from generic-webhook-trigger-plugin.
I tried like the below but its not triggering anything now:
After a manual scanning I can see the new key is available at the Jenkins filter as well:
from generic-webhook-trigger-plugin.
Related Issues (20)
- option 'avoid flatterning branches' is broken for JSONPath HOT 3
- Webhook secret doesn't work with GitHub HOT 9
- Finding Security Violation and operational Risks HOT 6
- Performance is slow for large installations HOT 18
- Getting no POST body in the Jenkins job HOT 2
- Same setting works in staging jenkins and doesn't work in Prod jenkins HOT 2
- Running sh without filling in a value for Post content parameters will blocking HOT 1
- Sometimes multiple variable contributions is shown HOT 3
- How can I get the raw json body? HOT 11
- GWT 1.88.1 breaks Jenkins job HOT 2
- groovy.lang.MissingPropertyException: No such property HOT 1
- Plugin does not accept Github token scheme HOT 7
- Reload trigger configuration from scm HOT 5
- Buildcause no longer detected since Jenkins update? HOT 3
- Not compatible with the "Trigger builds remotely" configuration option HOT 2
- The JSON response is not shown in Jenkins log, even if it is configured to be shown HOT 4
- Link is dead HOT 1
- Expose request JSON payload as an object in a variable
- All branches are triggered instead of one specific HOT 6
- Failed to invoke the trigger and get 500 error code HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from generic-webhook-trigger-plugin.