Reputation: 332
I am using jenkins job dsl to create pipelineJob, I do not know how to delete those jobs through the same plugin.
I wondered around in the code base, and I think it is not doable.
I thought of using the rest api to make a call to the api to delete a job, can anyone give me any lead on how to do that in groovy or extending a Java class.
Basically it would be:
Huuuge THANKS
Upvotes: 0
Views: 833
Reputation: 332
Finally, to meet my needs I had to make an api call.
It looks like this:
RestApiJobManagement jm = new RestApiJobManagement(baseUrl)
HttpResponseDecorator resp = jm.restClient.get(path: 'crumbIssuer/api/xml')
if (resp.status == 200) {
restClient.headers[resp.data.crumbRequestField] = resp.data.crumb
}
resp = jm.restClient.post(
path: '/job/${job.jobName}/doDelete',
requestContentType: 'charset=UTF-8'
)
println "status ${resp.status}"
The only issue is that I am unable to read through a jenkinsjobdsl.groovy file and get all job names to fill ${job.jobName}
Upvotes: 0
Reputation: 3690
I haven't used the scripts from here and here, but they look promising.
import jenkins.model.*
def matchedJobs = Jenkins.instance.items.findAll { job ->
job.name =~ /my_regex_here/
}
matchedJobs.each { job ->
println job.name
//job.delete();
}
If your jobs do not share a common pattern in the name and you cannot use Regex, here and here are some resources for reading files with groovy.
Upvotes: 1