Issue
I am trying to update a library in "Configuration" we use in Jenkins through Python, but do not see any way to do this through Jenkins API. Is there a way to update the version to 1.1.0
via Jenkins API?
Solution
Assuming you are ok with using a groovy script to configure the library version, you can use the following script to set the default version of an Global existing library:
def jenkins = Jenkins.getInstance()
def globalLibraryDescriptor = jenkins.getDescriptor("org.jenkinsci.plugins.workflow.libs.GlobalLibraries")
def config = globalLibraryDescriptor.getLibraries().find {
it.name == '1.1.0' // Find your existing library by name
}
config.setDefaultVersion("THE_NEW_VERION") // Update the default version value
If you also want to create library configurations in the global settings via API you can use the following script as a usage example for the groovy API.
If you want to configure a Folder level Existing library you can use the following code:
def jenkins = Jenkins.getInstance()
def folderLibrary = jenkins.getItem("FOLDER_NAME").getProperties().find {it.class =~ 'FolderLibraries'}
def config = folderLibrary.getLibraries().find {
it.name == '1.1.0' // Find your existing library by name
}
config.setDefaultVersion("THE_NEW_VERION") // Update the default version value
Answered By - Noam Helmer
Answer Checked By - Timothy Miller (JavaFixing Admin)