Created
March 16, 2019 12:41
-
-
Save marcosborges/d3aca2cbf265b17875530e06d775343c to your computer and use it in GitHub Desktop.
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
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