Fixed manipulation with global libraries in some weird cases
Change-Id: Ife4ca8c8d2c42820dc74246e6ad2a76d33047d46
diff --git a/_states/jenkins_lib.py b/_states/jenkins_lib.py
index 6492623..10ef75f 100644
--- a/_states/jenkins_lib.py
+++ b/_states/jenkins_lib.py
@@ -28,8 +28,12 @@
LibraryConfiguration library = new LibraryConfiguration("{lib_name}", retriever)
library.setDefaultVersion("{branch}")
library.setImplicit({implicit})
- globalLibsDesc.get().getLibraries().removeIf{{ it.name.equals("{lib_name}")}}
- globalLibsDesc.get().getLibraries().add(library)
+ if(globalLibsDesc.get().getLibraries().isEmpty()){{
+ globalLibsDesc.get().setLibraries([library])
+ }}else{{
+ globalLibsDesc.get().getLibraries().removeIf{{ it.name.equals("{lib_name}")}}
+ globalLibsDesc.get().getLibraries().add(library)
+ }}
print("SUCCESS")
}}
""" # noqa