Giter VIP home page Giter VIP logo

Comments (11)

tomasbjerre avatar tomasbjerre commented on June 2, 2024 1

Keep the key as it was, but change the others.

from generic-webhook-trigger-plugin.

Udayendu avatar Udayendu commented on June 2, 2024 1

@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.

tomasbjerre avatar tomasbjerre commented on June 2, 2024

You need to supply the webhook being sent to the plugin. Without it, I cannot investigate this.

from generic-webhook-trigger-plugin.

Udayendu avatar Udayendu commented on June 2, 2024

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.

tomasbjerre avatar tomasbjerre commented on June 2, 2024

Can you also supply a branch payload that should not trigger build?

from generic-webhook-trigger-plugin.

Udayendu avatar Udayendu commented on June 2, 2024

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.

Udayendu avatar Udayendu commented on June 2, 2024

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.

tomasbjerre avatar tomasbjerre commented on June 2, 2024

What is printed here for the branch event?
echo "Repo ref Id: ${changes_ref_ids}"

from generic-webhook-trigger-plugin.

Udayendu avatar Udayendu commented on June 2, 2024

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.

tomasbjerre avatar tomasbjerre commented on June 2, 2024

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.

Udayendu avatar Udayendu commented on June 2, 2024

I tried like the below but its not triggering anything now:

image

After a manual scanning I can see the new key is available at the Jenkins filter as well:

image

image

from generic-webhook-trigger-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.