Is it possible to create new freestyle project and add it to the dashboard view on Jenkins straight from the groovy script?
For example, I want to go through the list of all dependencies for a project. If a dependency is missing from the project list I want to fetch it, create freestyle project and then run the build.
I think this might be what you need:
@NonCPS
def createFreestyleProject(String projectName){
def parent = Jenkins.getInstance()
//Instantiate a new project
def project = new FreeStyleProject(parent, projectName);
//Set a description for the project
project.setDescription("Just a placeholder for a description")
//Create a parameter for the project
def parameterDefinitions = new ArrayList<ParameterDefinition>();
def name = "ParameterOne"
def defaultValue = "1"
def description = "Just a placeholder for a parameter description"
parameterDefinitions.add(new StringParameterDefinition(name, defaultValue, description))
//Create a job property for the project
def jobProperty = new ParametersDefinitionProperty(parameterDefinitions)
//Adding and saving the job property to the project
project.addProperty(jobProperty)
project.save()
parent.reload()
}
But before this you must do:
import com.cloudbees.groovy.cps.NonCPS
import hudson.model.FreeStyleProject
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.