Jenkins Declarative Pipeline + GitHub + Push Triggers + Wildcard Branches...

325 views
Skip to first unread message

Andy Coates

unread,
Oct 22, 2017, 9:51:11 PM10/22/17
to Jenkins Users
Hey,

I am having _so_ much trouble getting what I thought would be the simplest workflow working.

All I am trying to do is have GitHub trigger a Jenkins build on a push to various branches.

I was using the git() step initially but I couldn't seem to get it to use multiple branches, so I swapped to the extended syntax of:

               dir(JOB_BASE_NAME) {
                    checkout([$class: 'GitSCM',
                        branches: [[name: GIT_BRANCH]],
                        userRemoteConfigs: [[credentialsId: "foo", url: "https://github.com/foo/${JOB_BASE_NAME}.git"]]]
                    )
                }

With GIT_BRANCH set to use the same syntax that freestyle options allowed (wildcard, regex and such) I made a little progress with manual builds, but I'm hitting a brick wall with the polling logic/detection.  When I push the polling log shows:

ERROR: no such computer <old slave name>

I'm not sure what its trying to do but it seems like its trying to do something with the polling logic on a slave?  (our slaves are dynamic EC2 based so can vanish when not used)

What am I missing? :(  All I want is for Jenkins to build whatever branch GitHub tells it was pushed to.

Thanks.




Mark Waite

unread,
Oct 22, 2017, 10:27:50 PM10/22/17
to jenkins...@googlegroups.com
It seems like you're describing a use case for a multi-branch pipeline.

Freestyle projects with git scm allows the same job to build for changes on multiple branches, using the branch name matching mechanism you've described.  Unfortunately, that makes the change history and the build history very difficult to read, since it takes extra work to deduce the branch which selected for a specific build.

Multi-branch pipeline will create and delete jobs as needed so that you have one job for each branch. When a branch is created, a job is created.  When a branch is deleted, its job is deleted.

That keeps the history clean and simplifies things.

Would that work in your case?

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/887c265e-f28a-4784-b93b-02fa68fe95da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andy Coates

unread,
Oct 23, 2017, 12:52:04 AM10/23/17
to Jenkins Users

Hey Mark,

Ok so its more about the historic tracking - I'm starting to see where and how that plays a role now.

I tried the multibranch pipeline and I think I can make the setup work - in essence the result is the same as what I wanted, just that it has to scan for branch changes and such (but that's workable).

Triggers/Polling still doesn't seem to work though, it doesn't even seem to notice a push.  On my test branch that it detected (with a Jenkinsfile), the configuration shown via the UI doesn't have the GitHub Project or the "GitHub hook trigger for GITScm polling" option set.  Since this config was created from a Jenkinsfile it seems like it didn't detect the checkout() section to setup that part of the polling config? 

I'll keep digging around but if its possible to get the config options fully setup via a Jenkinsfile so when a branch is detected and a new job created so it correctly populates the GitHub fields, I think this will work nicely :)

Thanks!
Andy
Reply all
Reply to author
Forward
0 new messages