Reputation: 1016
I am writing a Jenkins plugin, and I want it to create a new job (in the perform(...)
method, as a build step).
I know that I can create a job like this:
FreeStyleProject proj =
Hudson.getInstance().createProject(FreeStyleProject.class, "New job");
and I can add properties to it using proj.addProperty(someJobProperty)
.
How can I then also add a build step to the project, programmatically, like the properties? Specifically, I would like to add an Execute shell and Copy Artifact build step.
I have been looking through the Jenkins JavaDoc, especially the Job page, and I haven't been able to find anything that would help me.
Upvotes: 1
Views: 2050
Reputation: 1016
The project has a method getBuildersList()
which returns the list of all the build steps. You can add a build step to the project by simply adding a build step to the list returned by this method. The object you are adding to the list must be a Builder
.
I did it like this (using the plugin from the Jenkins HelloWorld tutorial as an example):
proj.getBuildersList().add(new HelloWorldBuilder("Bobbly"));
This adds a Hello World build step to the project.
Similarly, there is a getPublishersList()
method which returns the list of all the post-build steps and contains Publisher
objects.
Upvotes: 1