Closed stupchiy closed 6 years ago
The naming of ref
and reference
is just names of a variable. I'll change it to same name to avoid confusion.
You need to consider the BRANCH_NAME
in the regexp filter. You may try changing your Jenkinsfile
to this (in all branches):
pipeline {
agent any
triggers {
GenericTrigger(
genericVariables: [
[key: 'ref', value: '$.ref'],
[key: 'repository', regexpFilter: '[^a-z_-]', value: '$.repository']
],
causeString: 'Triggered on $ref',
regexpFilterExpression: 'generic $ref',
regexpFilterText: '$repository refs/heads/' + BRANCH_NAME,
printContributedVariables: true,
printPostContent: true
)
}
stages {
stage('Test Generic Trigger') {
steps {
sh """
echo Variables from shell:
echo reference ${ref}
echo repository ${repository}
"""
}
}
}
}
hey @tomasbjerre, thanks for getting back fast. Now I can see more jobs identified with the same request:
{
"status":"ok",
"data":{
"triggerResults":{
"generic/pr1":{
"id":0,
"regexpFilterExpression":"generic $.ref",
"regexpFilterText":"generic refs/heads/pr1",
"resolvedVariables":{
"ref":"refs/heads/master",
"repository":"generic"
},
"triggered":false,
"url":""
},
"generic/master":{
"id":0,
"regexpFilterExpression":"generic $.ref",
"regexpFilterText":"generic refs/heads/master",
"resolvedVariables":{
"ref":"refs/heads/master",
"repository":"generic"
},
"triggered":false,
"url":""
}
}
}
}
but it doesn't trigger it right now with a request:
curl -X POST -i -H "Content-Type: application/json" --url 'https://my-jenkins-server.com/generic-webhook-trigger/invoke' -d '{ "ref": "refs/heads/master", "repository": "generic" }'
Am I doing something wrong?
btw, isn't it should be, instead?:
regexpFilterExpression: 'generic refs/heads/' + BRANCH_NAME,
regexpFilterText: '$repository $.ref',
In any case, no luck with that one as well
Thanks!
Sorry. "regexpFilterExpression":"generic $.ref",
should be regexpFilterExpression: 'generic $ref',
🤦♂️ I should have been noticed that. Thanks again @tomasbjerre. Still it should be, other way around:
regexpFilterExpression: 'generic refs/heads/' + BRANCH_NAME,
and
regexpFilterText: '$repository $ref',
Than it's working:
"generic/master": {
"id": 13340,
"regexpFilterExpression": "generic refs/heads/master",
"regexpFilterText": "generic refs/heads/master",
"resolvedVariables": {
"ref": "refs/heads/master",
"repository": "generic"
},
"triggered": true,
"url": "queue/item/13340/"
}
Thanks again for your efforts and plugin development 😉
Hey @tomasbjerre, I have kind of related question to that, since it's still not closed issue, I hope you wouldn't mind if I address it here. So everything above is working ok, but I have an issue when I am trying now to do the same with Pull Requests, I have "Suppress automatic SCM triggering" option enabled within the multi-branch pipeline, so it's not get triggered whenever new PR is opened within the github repo, but on my request using generic-webhook-trigger-plugin, but still creating job id's by indexing the repo. And it seems, it could not identify those jobs until they're not run at least once, but that's not good for the fresh PR's, since they will be never triggered. So I wonder, if I'm missing something again, or I always should do some kind of "fake" run within my pipeline, so generic-webhook-trigger-plugin can index such type of jobs afterwards? Thx
Im not sire exactly what you are doing and if it is possible. But what I do is combine Job DSL plugin and Pipeline plugin to have the DSL create a pull request job of type pipeline.
I configure this plugin with job dsl and the pipeline is just using whatever values i resolve. I usually create one pr pipeline per repo or just one global for any repo.
Oh wow, thanks for the fast reply! Ok, I'll try to explain on more simple example. Also, as to your example you've given - when you create a new item(job), are you able to trigger it with the generic-webhook-trigger-plugin, right after?
So, let's skip the multibranch pipeline. I've just created simple pipeline job, with the same pipeline we discussed above, from the very beginning, to make it simple. And at this point, it's never launched:
So, when I perform request to trigger it, with generic webhook:
curl -X POST -i -H "Content-Type: application/json" --url 'https://my-jenkins-server.com/generic-webhook-trigger/invoke' -d '{ "ref": "refs/heads/master", "repository": "generic" }'
I don't get a match and it's also not listed in a response body
But after I execute job once, manually, and trigger it with the same request again, I get it listed:
"generic-webhook-test": {
"id": 0,
"regexpFilterExpression": "generic $ref",
"regexpFilterText": "bla refs/heads/",
"resolvedVariables": {
"ref": "here",
"repository": "bla"
},
"triggered": false,
"url": ""
}
So it seems, it should be indexing pipeline, at least once, before it gets visible for generic-webhook-trigger-plugin ?
Yes it can be triggered immediately after creation.
Yes that is my understanding. You are creating a pipeline that configures properties of the job. So makes sense that it must first run once before those properties are applied to the job... But as I said, with job DSL you can have them applied immediately.
Alright, thanks! Will try to look into job DSL then. If you have any example to showcase that, would be awesome!
There is example in the readme.
Hi, since this issue isn't closed, and this is something I'm trying to do as well. I'm confused as to what variables are actually causing the right code to be checked out. Is it the regexpFilterExpression
, regexpFilterText
?
@madhukar93 Open a new issue.
master
branch andpr1
branch as well opened as pull-requestFrom the documentation it is not clear how do you use Generic Webhook plugin in combination with Multibranch pipeline, and in scripted pipeline there is
reference
variable is used, but declarative hasref
defined (not clear is that variable has some affect on which branch build to perform execution)Trying to trigger manually with curl:
and
Actual Result In both cases
master
job is triggeredExpected result Any possibility to trigger specific branch build(e.g.
https://my-jenkins-server.com/job/generic/job/develop/build
) or pr build (e.g.https://my-jenkins-server.com/job/generic/view/change-requests/job/PR-1/build
)