Skip to content

Instantly share code, notes, and snippets.

@imoutsatsos
Last active May 5, 2023 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imoutsatsos/c44b4ac14d074f665cb64ce116d637fc to your computer and use it in GitHub Desktop.
Save imoutsatsos/c44b4ac14d074f665cb64ce116d637fc to your computer and use it in GitHub Desktop.
//Generated by ChatGPT
import jenkins.model.*
import hudson.model.*
import hudson.XmlFile
def jobName = "my-job"
def configFilePath = "/path/to/config.xml"
def jenkins = Jenkins.getInstance()
def configFile = new XmlFile(new File(configFilePath))
if (jenkins.getItem(jobName) != null) {
println "Job '${jobName}' already exists."
} else {
def job = jenkins.createProjectFromXML(jobName, configFile)
job.save()
println "Job '${jobName}' created."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment