-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetJobXml.groovy
37 lines (32 loc) · 1.2 KB
/
getJobXml.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
pipeline {
agent any
stages {
stage('Generate Job XMLs') {
steps {
script {
// Get the workspace directory
def workspaceDir = env.WORKSPACE
// Iterate through all jobs
Jenkins.instance.getAllItems(Job.class).each { job ->
// Get job name and configuration as XML
def jobName = job.fullName
def jobXml = job.getConfigFile().asString()
// Create a file with the job's name and store the XML content
def fileName = "${workspaceDir}/${jobName.replace('/', '_')}.xml"
writeFile file: fileName, text: jobXml
// Print a message to indicate success
echo "Generated XML for job '${jobName}' and saved as '${fileName}'"
}
}
}
}
}
post {
success {
echo 'Job XMLs have been successfully generated and saved in the workspace.'
}
failure {
echo 'There was an error generating job XMLs.'
}
}
}