Last active
November 27, 2024 12:05
-
-
Save ivan-pinatti/454846b24987148803cf80bcd74ef562 to your computer and use it in GitHub Desktop.
Jenkins - Create a Jenkins view via groovy script - #jenkins #groovy #jenkins-view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!groovy | |
// imports | |
import jenkins.model.Jenkins | |
import hudson.model.ListView | |
// get Jenkins instance | |
Jenkins jenkins = Jenkins.getInstance() | |
// variables | |
def viewName = 'MyView' | |
// create the new view | |
jenkins.addView(new ListView(viewName)) | |
// get the view | |
myView = hudson.model.Hudson.instance.getView(viewName) | |
// add a job by its name | |
myView.doAddJobToView('MyJob1') | |
myView.doAddJobToView('MyJob2') | |
myView.doAddJobToView('MyJob3') | |
// save current Jenkins state to disk | |
jenkins.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just managed to add a regular expression filter to the view, here is how I did it:
To see allowed values, check documentation:
includeExcludeTypeString
- https://javadoc.jenkins-ci.org/plugin/view-job-filters/hudson/views/AbstractIncludeExcludeJobFilter.IncludeExcludeType.html#includeMatchedvalueTypeString
- https://javadoc.jenkins-ci.org/plugin/view-job-filters/hudson/views/RegExJobFilter.ValueType.html#NAME