indigo-dc / jenkins-pipeline-library

Jenkins pipeline library with common functionalities for CI/CD environments, mainly targeted for the implementation of the SQA baseline requirements from https://indigo-dc.github.io/sqa-baseline/
Apache License 2.0
11 stars 6 forks source link

Create plugin to import required jars for Validator #35

Open samuelbernardolip opened 4 years ago

samuelbernardolip commented 4 years ago

Plugin repository

https://github.com/WORSICA/indigo-dependencies

Development steps

Create plugin based on Hello World from the Jenkins reference base: https://github.com/jenkinsci/archetypes/

Since development plugin for archtypes seems to be out of maintenance until 2019, we can use JPI that also supports Groovy for Jenkins Plugin development: https://github.com/jenkinsci/gradle-jpi-plugin

For now I will only use archetypes to generate a base empty plugin. Plugin name convention and style guide: https://www.jenkins.io/doc/developer/publishing/style-guides/

Generate project template using archtypes:

git clone git@github.com:jenkinsci/archetypes.git
cd archetypes
mvn archetype:generate -B -DarchetypeGroupId=io.jenkins.archetypes -DarchetypeArtifactId=empty-plugin -DarchetypeVersion=1.6 -DartifactId=indigo-dependencies

Generated project code will be in sub-directory indigo-dependencies. It is possible to run again to update to a newer archetype version anytime.

To build plugin HPI only need to run inside the project directory: mvn install

This will create the file ./target/indigo-dependencies.hpi that you can deploy to Jenkins.

Note: review plugin classloader hierarchy to understand how dependencies are loaded https://www.jenkins.io/doc/developer/plugin-development/dependencies-and-class-loading/

Plugin publishing into Jenkins marketplace

We must add a jenkinsfile to run the tests and do the plugin validation. To test the plugin, the following command will start a jenkins instance that can be used for the required plugin functional testing: mvn hpi:run

References quick development guide:

https://www.jenkins.io/doc/developer/publishing/style-guides/ https://www.jenkins.io/doc/developer/tutorial/prepare/ https://www.jenkins.io/doc/developer/tutorial/create/ https://www.jenkins.io/doc/developer/tutorial/run/ https://www.jenkins.io/doc/developer/tutorial/extend/ https://wiki.jenkins.io/display/JENKINS/Plugin+tutorial

samuelbernardolip commented 4 years ago

Because of Jenkins security restrictions, I need to create the step indigoValidator that allow to run the validator code with its required dependencies. But the Java implementation have data binding issues when collecting the expected config.yml and schema.json (casting from Groovy into Java).

Run groovy code using GroovyShell from Java code side https://www.programcreek.com/java-api-examples/?class=groovy.lang.GroovyShell&method=evaluate

Since there are data binding problems when running Validator code using Java implementation from Groovy shared library, using GroovyShell could allow to run validate with the original groovy code and see if it solves the present issues.

samuelbernardolip commented 4 years ago

As concluded in issue #27 plugin will be integrated together with jpl-validator within the library: