Declarative Pipeline via Jenkinsfile - how to set GitHub push trigger job option.

3,610 views
Skip to first unread message

Andy Coates

unread,
Oct 24, 2017, 9:32:10 AM10/24/17
to Jenkins Users
Hey,

I keep seeing reference to a properties function like this:

properties([ pipelineTriggers([ [$class: "GitHubPushTrigger"] ]) ])

The description and functionality appears to do what the UI option "GitHub hook trigger for GITScm polling" does.

Unfortunately this doesn't seem to exist in the current declarative pipeline at a top level config.

If I look at https://jenkins.io/doc/pipeline/steps/workflow-multibranch/ (since I'm working with multibranch) it has a 'properties' step section, and in Jenkins the Pipeline Syntax generator for 'properties' step gives me an example of:

properties([[$class: 'GithubProjectProperty', displayName: '', projectUrlStr: 'https://github.com/foo/bar/'], pipelineTriggers([githubPush()])])

However the documentation and that syntax generator appear to generate a step that doesn't exist - Jenkins throws an error:

WorkflowScript: 30: Invalid step "properties" used - not allowed in this context - The properties step cannot be used in Declarative Pipelines

I feel like I'm going around in circles here :(  Help!

Thanks.

Robert Hales

unread,
Oct 24, 2017, 10:46:59 AM10/24/17
to Jenkins Users
Does this work if you put it inside a stage{steps{script{}}}?  Properties are not supported like that in Declarative (as it say), but you may be able to just run it in the script (basically dropping out of declarative). 

Andy Coates

unread,
Oct 24, 2017, 9:03:06 PM10/24/17
to Jenkins Users
Thanks, yes it actually works if I put it inside a script {}.

I find this very very confusing as a new user to pipelines, the documentation seems all over the place :(

Now I just need to stop it building the same commit that was push triggered when it Branch Indexes.

Robert Hales

unread,
Oct 24, 2017, 9:09:56 PM10/24/17
to Jenkins Users
Declarative pipeline is meant to be an easier pipeline with a lower cost of entry in terms of learning and getting up and going. It isn't necessarily meant to be able to do everything, though it tends to support more and more. If you want to do everything possible, you drop back to the scripted pipeline where you can truly code the pipeline and get into the meat of what can be done. Fortunately, they made it easy to bring the two together pretty easily. 
Reply all
Reply to author
Forward
0 new messages