是否可以直接从groovy脚本创建新的自由式项目并将其添加到Jenkins的仪表板视图中?
例如,我想浏览项目的所有依赖项列表。如果要从项目列表中缺少依赖项,请创建自由样式项目,然后运行构建。
答案 0 :(得分:1)
我认为这可能是您所需要的:
@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()
}
但是在此之前,您必须执行以下操作:
import com.cloudbees.groovy.cps.NonCPS
import hudson.model.FreeStyleProject