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

Pipelines inside a Multibranch Pipeline not being found #314

Closed
matheushoeltgebaum opened this issue Jun 19, 2024 · 9 comments
Closed

Pipelines inside a Multibranch Pipeline not being found #314

matheushoeltgebaum opened this issue Jun 19, 2024 · 9 comments
Labels

Comments

@matheushoeltgebaum
Copy link

Jenkins and plugins versions report

I have a Multibranch Pipeline mapped to a Git repository, hosted in our company server. I was looking for a way to trigger the pipelines defined inside this multibranch project, and found this plugin.

So far, those pipelines are not being found, when I do a request to Jenkins. I'm getting the following error:

{"jobs":null,"message":"Did not find any jobs with GenericTrigger configured!\nA token was supplied.\n"}* Connection #0 to host JENKINS-SERVER left intact

I'm using a Jenkins file inside our repository, to configure the pipeline, with the declarative syntax. Here's how the triggers section is defined:

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

      token: 'abc123',
      tokenCredentialId: '',

      causeString: 'Triggered on $ref',

      printPostContent: true,
      printContributedVariables: true,

      silentResponse: false,
      shouldNotFlatten: false,

      regexpFilterExpression: 'refs/heads/' + BRANCH_NAME,
      regexpFilterText: '$ref'
    )
  }

And here is how this configuration is applied in Jenkins:
image
image
image
image

I'm using the following Curl command:
curl -vs "http://JENKINS-SERVER/generic-webhook-trigger/invoke?token=abc123"

However, if I create a simple pipeline, using the same generic webhook trigger configuration as above, then the job is found when I do the same Curl command, getting the response below:

{"jobs":{"DSTeste":{"regexpFilterExpression":"refs/heads/master","triggered":false,"resolvedVariables":{"ref":""},"regexpFilterText":"","id":0,"url":""}},"message":"Triggered jobs."}* Connection #0 to host JENKINS-SERVER left intact

Expected result

Pipelines inside a multibranch project should be found

Actual result

Pipelines inside a multibranch project are not being found

Jenkins and plugins versions report

Jenkins: 2.426.3
OS: Linux - 5.15.0-58-generic
Java: 11.0.16 - Eclipse Adoptium (OpenJDK 64-Bit Server VM)

ace-editor:1.1
ansicolor:1.0.4
apache-httpcomponents-client-4-api:4.5.14-208.v438351942757
asm-api:9.7-33.v4d23ef79fcc8
bootstrap5-api:5.3.2-3
bouncycastle-api:2.30.1.77-225.v26ea_c9455fd9
branch-api:2.1144.v1425d1c3d5a_7
caffeine-api:3.1.8-133.v17b_1ff2e0599
checks-api:2.0.2
cloudbees-folder:6.858.v898218f3609d
command-launcher:107.v773860566e2e
commons-lang3-api:3.13.0-62.v7d18e55f51e2
commons-text-api:1.11.0-95.v22a_d30ee5d36
credentials:1319.v7eb_51b_3a_c97b_
credentials-binding:657.v2b_19db_7d6e6d
dependency-track:4.3.1
discord-notifier:241.v448b_ccd0c0d6
display-url-api:2.200.vb_9327d658781
durable-task:547.vd1ea_007d100c
echarts-api:5.4.3-2
font-awesome-api:6.5.1-2
generic-webhook-trigger:2.2.1
git:5.2.1
git-client:4.6.0
gson-api:2.10.1-15.v0d99f670e0a_7
instance-identity:185.v303dc7c645f9
ionicons-api:56.v1b_1c8c49374e
jackson2-api:2.16.1-373.ve709c6871598
jakarta-activation-api:2.0.1-3
jakarta-mail-api:2.0.1-3
javax-activation-api:1.2.0-6
javax-mail-api:1.6.2-9
jaxb:2.3.9-1
jdk-tool:73.vddf737284550
joda-time-api:2.12.6-21.vca_fd74418fb_7
jquery3-api:3.7.1-1
jsch:0.2.16-86.v42e010d9484b_
json-path-api:2.9.0-58.v62e3e85b_a_655
junit:1256.v002534a_5f33e
locale:431.v3435fa_8f8445
mailer:463.vedf8358e006b_
matrix-project:822.824.v14451b_c0fd42
mina-sshd-api-common:2.12.0-90.v9f7fb_9fa_3d3b_
mina-sshd-api-core:2.12.0-90.v9f7fb_9fa_3d3b_
msbuild:1.30
okhttp-api:4.11.0-172.vda_da_1feeb_c6e
pipeline-build-step:540.vb_e8849e1a_b_d8
pipeline-graph-analysis:202.va_d268e64deb_3
pipeline-groovy-lib:704.vc58b_8890a_384
pipeline-input-step:477.v339683a_8d55e
pipeline-milestone-step:111.v449306f708b_7
pipeline-model-api:2.2175.v76a_fff0a_2618
pipeline-model-definition:2.2175.v76a_fff0a_2618
pipeline-model-extensions:2.2175.v76a_fff0a_2618
pipeline-stage-step:305.ve96d0205c1c6
pipeline-stage-tags-metadata:2.2175.v76a_fff0a_2618
plain-credentials:182.v468b_97b_9dcb_8
plugin-util-api:3.8.0
popper2-api:2.11.6-4
postbuild-task:1.9
scm-api:683.vb_16722fb_b_80b_
script-security:1313.v7a_6067dc7087
snakeyaml-api:2.2-111.vc6598e30cc65
sonar:2.17.1
ssh-credentials:308.ve4497b_ccd8f4
sshd:3.303.vefc7119b_ec23
structs:337.v1b_04ea_4df7c8
trilead-api:2.133.vfb_8a_7b_9c5dd1
variant:60.v7290fc0eb_b_cd
workflow-aggregator:596.v8c21c963d92d
workflow-api:1291.v51fd2a_625da_7
workflow-basic-steps:1042.ve7b_140c4a_e0c
workflow-cps:3853.vb_a_490d892963
workflow-durable-task-step:1317.v5337e0c1fe28
workflow-job:1385.vb_58b_86ea_fff1
workflow-multibranch:773.vc4fe1378f1d5
workflow-scm-step:415.v434365564324
workflow-step-api:657.v03b_e8115821b_
workflow-support:865.v43e78cc44e0d

@tomasbjerre
Copy link
Contributor

Remove the regexp filter. Or supply a json body in the curl command that matches the regexp.

@matheushoeltgebaum
Copy link
Author

Tried both suggestions, but still got the same message that no job was found.

I did the following Curl command, to provide the json body:

curl -v "http://JENKINS-SERVER/generic-webhook-trigger/invoke?token=abc123" -H "Content-Type: application/json" -d "{\"ref\": \"refs/heads/master\"}"

Then, I removed both "regexpFilterExpression" and "regexpFilterText" from my Jenkinsfile, like below:

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

      token: 'abc123',
      tokenCredentialId: '',
      causeString: 'Triggered on $ref',
      printPostContent: true,
      printContributedVariables: true,
      silentResponse: false,
      shouldNotFlatten: false,
      regexpFilterExpression: '',
      regexpFilterText: ''
    )
  }

And tried the following Curl command:

curl -vs "http://JENKINS-SERVER/generic-webhook-trigger/invoke?token=abc123"

@tomasbjerre
Copy link
Contributor

You can clone this repo and debug that configuration, I will not have time to do that for a few days.

This might be related to #311 and #312, but it is a long shot. If so it was fixed in latest Jenkins LTS (jenkinsci/jenkins#9304 jenkinsci/jenkins#9303). Maby try with Jenkins 2.452.2.

@tomasbjerre
Copy link
Contributor

tomasbjerre commented Jun 26, 2024

I tried this here:
https://github.com/tomasbjerre/gwt-issue-314/

I can trigger it with:

curl -v "http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=abc123" -d '{ "ref": "refs/heads/main"}' -H "Content-Type: application/json"

Using Jenkins 2.452.2.

@CarryWll
Copy link

I also encountered the same problem. How can I resolve it?

@matheushoeltgebaum
Copy link
Author

* Did you add a build-step?

Yes, here's my Jenkinsfile:

pipeline {
  agent { label 'WinSlaveDELIVERERDSV2' }
  options {
    buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '10', daysToKeepStr: '', numToKeepStr: '10')
    disableConcurrentBuilds()
  }
  triggers {
    GenericTrigger(
      genericVariables: [
        [key: 'ref', value: '$.ref']
      ],

      token: 'abc123',
      tokenCredentialId: '',

      causeString: 'Triggered on $ref',

      printPostContent: true,
      printContributedVariables: true,

      silentResponse: false,
      shouldNotFlatten: false,

      regexpFilterExpression: '',
      regexpFilterText: ''
    )
  }
  stages {
    stage('Hello') {
      steps {
        echo 'hello'
        bat 'echo $ref'
      }
    }
  }
}
* Did you supply the `Content-Type: application/json` header?

Yes, I have done that, using the following command:

curl -v "http://JENKINS-SERVER/generic-webhook-trigger/invoke?token=abc123" -H "Content-Type: application/json" -d "{\"ref\": \"refs/heads/master\"}"

I managed a workaround, using the "multibranch-scan-webhook-trigger" plugin, to trigger the pipelines. It's not ideal, since it's going to trigger everything, but it's alright for our current scenario.

I believe the problem it's related to Jenkins itself, using the latest version will probably fix this. I'm planning on updating it, but I won't have time to do it for a few days. So I'm going to close this issue for now. If updating Jenkins won't fix this, I'll reopen it.

Anyway, thank you for your help so far @tomasbjerre!

@CarryWll
Copy link

CarryWll commented Jul 1, 2024

* Did you add a build-step?

Yes, here's my Jenkinsfile:

pipeline {
  agent { label 'WinSlaveDELIVERERDSV2' }
  options {
    buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '10', daysToKeepStr: '', numToKeepStr: '10')
    disableConcurrentBuilds()
  }
  triggers {
    GenericTrigger(
      genericVariables: [
        [key: 'ref', value: '$.ref']
      ],

      token: 'abc123',
      tokenCredentialId: '',

      causeString: 'Triggered on $ref',

      printPostContent: true,
      printContributedVariables: true,

      silentResponse: false,
      shouldNotFlatten: false,

      regexpFilterExpression: '',
      regexpFilterText: ''
    )
  }
  stages {
    stage('Hello') {
      steps {
        echo 'hello'
        bat 'echo $ref'
      }
    }
  }
}
* Did you supply the `Content-Type: application/json` header?

Yes, I have done that, using the following command:

curl -v "http://JENKINS-SERVER/generic-webhook-trigger/invoke?token=abc123" -H "Content-Type: application/json" -d "{\"ref\": \"refs/heads/master\"}"

I managed a workaround, using the "multibranch-scan-webhook-trigger" plugin, to trigger the pipelines. It's not ideal, since it's going to trigger everything, but it's alright for our current scenario.

I believe the problem it's related to Jenkins itself, using the latest version will probably fix this. I'm planning on updating it, but I won't have time to do it for a few days. So I'm going to close this issue for now. If updating Jenkins won't fix this, I'll reopen it.

Anyway, thank you for your help so far @tomasbjerre!

* Did you add a build-step?

Yes, here's my Jenkinsfile:

pipeline {
  agent { label 'WinSlaveDELIVERERDSV2' }
  options {
    buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '10', daysToKeepStr: '', numToKeepStr: '10')
    disableConcurrentBuilds()
  }
  triggers {
    GenericTrigger(
      genericVariables: [
        [key: 'ref', value: '$.ref']
      ],

      token: 'abc123',
      tokenCredentialId: '',

      causeString: 'Triggered on $ref',

      printPostContent: true,
      printContributedVariables: true,

      silentResponse: false,
      shouldNotFlatten: false,

      regexpFilterExpression: '',
      regexpFilterText: ''
    )
  }
  stages {
    stage('Hello') {
      steps {
        echo 'hello'
        bat 'echo $ref'
      }
    }
  }
}
* Did you supply the `Content-Type: application/json` header?

Yes, I have done that, using the following command:

curl -v "http://JENKINS-SERVER/generic-webhook-trigger/invoke?token=abc123" -H "Content-Type: application/json" -d "{\"ref\": \"refs/heads/master\"}"

I managed a workaround, using the "multibranch-scan-webhook-trigger" plugin, to trigger the pipelines. It's not ideal, since it's going to trigger everything, but it's alright for our current scenario.

I believe the problem it's related to Jenkins itself, using the latest version will probably fix this. I'm planning on updating it, but I won't have time to do it for a few days. So I'm going to close this issue for now. If updating Jenkins won't fix this, I'll reopen it.

Anyway, thank you for your help so far @tomasbjerre!

I have added build-step. I also supply the'Content-Type: application/json 'header. In multi-branch pipeline tasks, it cannot be triggered automatically, but it can be triggered normally in normal pipelines. Currently my Jenkins is version 2.455.

@tomasbjerre
Copy link
Contributor

@CarryWll open new issue

@tomasbjerre
Copy link
Contributor

This might be same as #319 .

@jenkinsci jenkinsci locked and limited conversation to collaborators Jul 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants