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]: "Library Providing Plugin" bug requires src/ directory within libraries #268

Closed connorh23 closed 2 years ago

connorh23 commented 2 years ago

Jenkins Version

Jenkins 2.289.1

JTE Version

2.3

Bug Description

The following line (128) in PluginLibraryProvider.groovy checks if a library directory is valid. It does so by inspecting the presence of steps/ and src/ directories within the library. However, it would seem that there is a bug introduced by employing the || operator instead of the && operator.

By using the || operator, both steps and classes are required. If && was employed, then a library implementing only steps or classes would be considered valid.

Given the plugin example presented here & other library development practices, it would appear that && is the desired behavior.

My present workaround is to include dummy content within the library directory, which is not an ideal solution to carry forward.

i.e.

### This works
libraries/
   exampleLibrary/
      steps/
         exampleStep.groovy
      src/
         foo.groovy

### This does not
libraries/
   exampleLibrary/
      steps/
         exampleStep.groovy

Thanks :)

Relevant log output

17:04:07  Started by user unknown or anonymous
17:04:07 [2022-04-27T00:04:07.857Z] [JTE] Pipeline Configuration Modifications 
17:04:07  [JTE] Configurations Added:
17:04:07  [JTE] - libraries.libraryA set to [:]
17:04:07  [JTE] Configurations Deleted: None
17:04:07  [JTE] Configurations Changed: None
17:04:07  [JTE] Configurations Duplicated: None
17:04:07  [JTE] Configurations Ignored: None
17:04:07  [JTE] Subsequent May Merge: None
17:04:07  [JTE] Subsequent May Override: None
17:04:08  [JTE] Library libraryA exists but does not have any steps or classes. Will not be loaded.
17:04:08 [2022-04-27T00:04:08.079Z] [JTE] The following errors occurred:  
17:04:08  [JTE] 1: Library libraryA not found.

Steps to Reproduce

  1. Create a new plugin by cloning the following repository
  2. Build & install the plugin
  3. Configure a job to use the new library. For simplicity, ignore other pipeline configurations & include a similar Jenkinsfile
    pipeline {
    stages {
        stage('Example Build') {
            steps {
              script {
                exampleStep()
              }
          }
        }
    }
    }

and pipeline configuration

libraries {
    libraryA
}
  1. Run the pipeline & observe the inability to load & use libraryA, as shown in logs above.
steven-terrana commented 2 years ago

hey @connorh23 great catch!

Looks like you're right.

Would you like to open the Pull Request with the fix?