Skip to content

Instantly share code, notes, and snippets.

@marcosborges
Created March 16, 2019 12:41
Show Gist options
  • Save marcosborges/d3aca2cbf265b17875530e06d775343c to your computer and use it in GitHub Desktop.
Save marcosborges/d3aca2cbf265b17875530e06d775343c to your computer and use it in GitHub Desktop.
import jenkins.model.Jenkins;
class Folders{
def static all(){
return Jenkins
.getInstance()
.getAllItems(com.cloudbees.hudson.plugins.folder.Folder.class)
.toArray()
}
def static find(name){
return Jenkins
.getInstance()
.getAllItems(com.cloudbees.hudson.plugins.folder.Folder.class)
.find({ it.getFullName() == name})
}
def static exists(name){
def itens = Jenkins
.getInstance()
.getAllItems(com.cloudbees.hudson.plugins.folder.Folder.class)
.find({ it.getFullName() == name}) != null
}
def static create(folder, name){
if(folder == null){
return Jenkins
.getInstance().createProject(
com.cloudbees.hudson.plugins.folder.Folder.class,
name
)
} else {
return folder
.createProject(
com.cloudbees.hudson.plugins.folder.Folder.class,name
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment