GithubHelp home page GithubHelp logo

jenkinsci / pipeline-global-lib-nexus-plugin Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 6.0 112 KB

Allows Jenkins to pull shared libraries from Nexus

Home Page: https://plugins.jenkins.io/pipeline-global-lib-nexus/

License: MIT License

Java 93.03% HTML 6.97%

pipeline-global-lib-nexus-plugin's Introduction

Pipeline groovy libraries: Nexus plugin

Jenkins Plugin GitHub release Jenkins Plugin Installs

The official pipeline-groovy-lib-plugin does provide a way to retrieve shared libraries through a SCM, such as Git. The goal of this Nexus plugin is to add the ability to retrieve shared libraries from Nexus (via the @Library declaration in a Jenkinsfile).

Installation of the plugin

Installation using a pre-built artifact

Installing from the plugins site (recommended)

The plugin is referenced as an official plugin on the Jenkins update site, so you should be able to use the integrated search in the Plugin section.

Install the plugin using the pre-built .hpi file

You can find the archives of all the versions of the Plugin on the Jenkins update site. You can also download the wished plugin release from the GitHub releases section. Then, go to the Jenkins Administration Plugins UI > Advanced section and upload the plugin .hpi file.

Installation from source

You can follow the steps hereafter to install the plugin:

How to use the plugin

Pre-requisite: a packaged shared library

In order to be able to use this plugin, you need to package your library (probably during a Continuous Integration build) and publish it to Nexus so Maven can download the artifact again. You should end up with a ZIP file with the following structure:

> unzip -vl pipeline-libraries.zip
Archive:  pipeline-libraries.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
     xxx  Defl:N      xxx  37% 03-21-2019 12:14 7d354e1f  resources/a-rsc-needed
    xxxx  Defl:N     xxxx  68% 03-21-2019 12:14 fefba77f  src/your/package/YourGroovyClass.groovy
     xxx  Defl:N      xxx  33% 03-21-2019 12:14 5b6808ab  vars/yourvar.groovy
     xxx  Defl:N      xxx  39% 03-21-2019 12:14 5842cc52  vars/yourvar.txt
--------          -------  ---                            -------
  xxxxxx           xxxxxx  x%                            n files

If you want to package it like this with maven, you can use the following. In your pom.xml

<build>
   <plugins>
      <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.6</version>
            <executions>
               <execution>
                  <configuration>
                        <finalName>your-library</finalName>
                        <descriptors>
                           <descriptor>assembly.xml</descriptor>
                        </descriptors>
                  </configuration>
                  <id>make-assembly1</id>
                  <phase>package</phase>
                  <goals>
                        <goal>single</goal>
                  </goals>
               </execution>
            </executions>
      </plugin>
   </plugins>
</build>

The assembly.xml file:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
  <id>lib</id>

  <formats>
    <format>zip</format>
  </formats>

  <includeBaseDirectory>false</includeBaseDirectory>

  <fileSets>
    <fileSet>
      <directory>.</directory>
      <outputDirectory>/</outputDirectory>
      <lineEnding>unix</lineEnding>
      <includes>
        <include>src/**</include>
        <include>vars/**</include>
        <include>resources/templates/*.json</include>
        <include>resources/*.sh</include>
        <include>version.txt</include>
      </includes>
    </fileSet>
  </fileSets>

</assembly>

A basic example project is available here, which contains a scripted pipeline executing a couple of basic steps.

Constraints

The plugin only supports ZIP shared libraries for the moment.

Setup of the plugin

The plugin is configurable on the Jenkins UI, at different levels:

  • On Global System Configuration page (Administration)
  • On Folder Configuration page
  • On Pipeline Configuration page

Jenkins administrators can set global libraries on the Administration page, while Jenkins users can set libraries either on the Folder view or on the Pipeline view.

The generic documentation to reference a new shared library can be found here.

In the Jenkins UI

In Administration / Folder / Pipeline configuration views:

  • Go to the Global Pipeline Libraries section and add a new library. You should see 3 different retrieval methods: Modern SCM, Nexus and Legacy SCM.
  • Give it a name and a default version
  • Decide if you want to load it implicitly or not Administration UI
  • Provide the artifact details used to retrieve the shared libraries in the following format: <groupId>:<artifactId>:<version>:<packaging>:<optional classifier>. In the example the following shared library is used: com.roylenferink:jenkins-shared-library:${library.jenkins-lib.version}:zip:lib.
  • Provide a location to an available Maven installation. If MAVEN_HOME is not specified, the first-found Maven installation will be used. If Maven cannot be found the job will fail. In the example the following Maven location is used /tools/apache-maven-3.6.2.

The artifact details are version-dynamic, it follows the Jenkins standard annotation ${library.<library_name>.version} that is afterwards replaced either by the default version provided by the admin, or the version specified by the user Jenkinsfile in the @Library annotation.

Directly in the Jenkinsfile

Users can also retrieve shared libraries from their Jenkinsfile, by defining it with this syntax:

library identifier: '[email protected]', retriever: nexus(
   artifactDetails: 'com.roylenferink:jenkins-shared-library:${library.external-shared-libraries.version}:zip:lib',
   mavenHome: '/tools/apache-maven-3.6.2')

Contributing to this plugin

Contributions to this plugin are definitely welcome! Follow the steps in the DEVELOPMENT.md to get started.

License

This project is licensed under the terms of the MIT License.

pipeline-global-lib-nexus-plugin's People

Contributors

dependabot[bot] avatar rlenferink avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pipeline-global-lib-nexus-plugin's Issues

Use Maven from Jenkins toolbox

Right now the plugin expects Maven to be in the PATH of the Jenkins master, however it would be more robust if a Maven version from the Jenkins toolbox could be selected as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.