jenkinsci / templating-engine-plugin

create tool-agnostic, templated pipelines to be shared by multiple teams
https://jenkinsci.github.io/templating-engine-plugin/latest/
Apache License 2.0
171 stars 58 forks source link

[Bug]: JTE libraries plugin does not load libraries without WebUI Apply/Save button #337

Open kirill-a opened 7 months ago

kirill-a commented 7 months ago

Jenkins Version

CloudBees Jenkins Enterprise 2.346.4.1-rolling

JTE Version

2.5.3

Bug Description

When I programmatically update folder's config.xml with JTE libraries packaged as a plugin, they don't load during job execution. After that, I open the folder in Web UI and press Apply/Save without changing anything, now library works as expected. Tried restarting Jenkins controller, it didn't help.

Is there any way to load libraries from plugin programmatically?

Steps to Reproduce

Prerequisite: JTE libraries packaged as a plugin and installed in Jenkins

When I programmatically update folder's config.xml with plugin config libraries, they don't load:

<librarySources>
   <org.boozallen.plugins.jte.init.governance.libs.LibrarySource>
       <libraryProvider class="org.boozallen.plugins.jte.init.governance.libs.PluginLibraryProvider">
           <plugin class="jte.generated.a8a8a19c2afe944718b0dd663d210afc0.LibrarySourcePlugin" plugin="lib@1.0.0" />
           <libraries class="linked-hash-map" />
           <jarLastModified>0</jarLastModified>
       </libraryProvider>
   </org.boozallen.plugins.jte.init.governance.libs.LibrarySource>
</librarySources>

Job log:

[JTE] 2: Library git not found.  
[JTE] java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...

After that, I open the folder in Web UI and press Apply/Save without changing anything, now library works as expected.

cokieffebah commented 5 months ago

replicated behavior by adding an SCM library source to an existing job.

cokieffebah commented 4 months ago

@kirill-a could you describe what you did to 'programmatically update folder's config.xml'? Did you call an API with the file? if so, include the command line and the file sent Did you run a script from locahost:8080/script ? if so, include the commands Did you run a command/script on the jenkins server/container ? if so, include the commands. Thanks

faridelmouhsine commented 2 months ago

Hi @kirill-a If you use jenkins-cli.jar to create the jobs prograamatically from config.xml you need to reload job configuration using reload-configuration option so the job gets is loaded from xml config file Regards Farid