Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple pipelines not triggering #292

Open
groliffe opened this issue Nov 29, 2022 · 1 comment
Open

Multiple pipelines not triggering #292

groliffe opened this issue Nov 29, 2022 · 1 comment

Comments

@groliffe
Copy link

I would have put this is a Discussion, but couldn't create one, so I don't know if this is really an issue or just something I'm doing wrong.

Jenkins : 2.361.2
PPR Plugin : 2.8.3

I’m trying to set up PPR to work on multiple pipelines, and I just cannot get it to work :

Here’s my setup.

Pipeline A.

This should be triggered whenever a push is made to repository ‘origin/X’

This is set up with a PPR Bitbucket Cloud Push with an Allowed Branch set to ‘X’

Pipeline B.

This should be triggered when a Pull Request for repository origin/RC- gets merged into repository origin/master.

This is set up with a PPR Bitbucket Cloud Pull Request, with an action of Merged, and an Allowed Branch of ‘master’

There is a ’Bitbucket Push and Pull Request Hook Log’ item added to the menu on each Pipeline.

Pipeline A gets triggered on a push as expected.

Pipeline B never gets triggered, unless I disable Pipeline A.

So, the hook log on Pipeline B doesn’t have anything in it unless I disable Pipeline A.

With both pipelines enabled, only the hook log on Pipeline A gets updated - and I can see it gets updated when the merge to master is done… and what it looks like is happening is that pipeline A gets the trigger - decides that it’s not for itself and then the process stops, and Pipeline B never gets triggered.

Does anyone have any ideas of how to get this working?

Cheers

Lance

@martens-d
Copy link

martens-d commented Feb 22, 2023

Hi,
create a third pipeline that gets triggered on both events and start pipeline A or B depending on what the payload says. And disable the trigger on A and B.

import groovy.json.JsonOutput;
import groovy.json.JsonSlurperClassic;
import java.text.SimpleDateFormat;

pipeline
{
  agent any
  
  stages
  {
    stage ('PPR')
    {
      steps
      {
        echo "stage PPR #####################################"
        script
        {
          if (env.BITBUCKET_PULL_REQUEST_ID != null) 
          {
            // it's a Pull Request
            // use curl to get more info
            def pretty = parseJsonToMap(env.BITBUCKET_PAYLOAD);

            prId = pretty.pullRequest.id;
            slug = pretty.pullRequest.fromRef.repository.slug;
            key  = pretty.pullRequest.fromRef.repository.project.key;

            withCredentials([usernameColonPassword(credentialsId: '###', variable: "API_TOKEN")]) {
              response = sh(script: " \"C:\\Program Files\\curl\\bin\\\\\"curl -u ${API_TOKEN} -H \"Content-Type: application/json\" https://bitbucket/rest/api/1.0/projects/${key}/repos/${slug}/pull-requests/${prId} ", returnStdout: true)
            }

            def json = parseJsonToMap(response);
            def state = json.state;
            def prinfo = json.fromRef.displayId + ' nach ' + json.toRef.displayId;

            // now you have all kind of infos
            if (state == "OPEN")
            {
              // PR Status
              prUnApproved = 0;
              json.reviewers.each{ item ->
                if (!item.approved.toBoolean())
                {
                  prUnApproved += 1;
                }
              }
              if (prUnApproved == 0)
              {
                prText = "Pull Request is aproved";

                ....
              } else {
                prText = "Prease aprove Pull Request";
                ...

                // build job A or B the one for Pull Request
                build job: '###', 
                  parameters: []
                  wait: true
                ...
            }

            if (state == "MERGED")
            {
              ...
            }
          } else {
          // not an Pull Request
          // maybe something similar to above
          // build job A or B the one for Push
          }      

Not a working example, I (want) to use it to add MessageCards in Teams, but have trouble with multiple repos and absurd naming of the folders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants