Questions tagged [jenkins-shared-libraries]

jenkins-shared-libraries is about the global shared libraries you're able to use in jenkins on conjunction with the Jenkins pipeline plugin (formerly known as workflow plugin).

jenkins-shared-libraries is about the global shared libraries you're able to use in jenkins on conjunction with the Jenkins pipeline plugin (formerly known as workflow plugin). See also: https://jenkins.io/doc/book/pipeline/shared-libraries/

136 questions
1
vote
1 answer

Jenkins - set options in a shared library for all pipelines that use the shared library

I have a bunch of repositories which use (parts of) the same Jenkins shared library for running tests, docker builds, etc. So far the shared library has greatly reduced the maintenance costs for these repos. However, it turned out that basically all…
1
vote
0 answers

Jenkins Transitive Dependency between Global Pipeline Libraries

My setup includes 2 Jenkins pipeline libraries, e.g. lib_generic and lib_specialized, where the second one depends on the first one (will call classes and global vars from the first one). I have to write my Jenkinsfile with the @library header that…
Patrice M.
  • 4,209
  • 2
  • 27
  • 36
1
vote
0 answers

Accessing SharedLibrary HEAD Commit-ID in build

We are using Jenkins and our build relies heavily on SharedLibraries. In our build we want to get the HEAD Commit-ID of our SharedLibrary. Do you have an idea how to manage this? Is there a default location where the checkout out shared library is…
1
vote
0 answers

How to retrieve a name (not a pull request number!) of my GitHub branch in Jenkinsfile

I have the following problem. I have a Jenkinsfile where I list the shared libraries I want to import in the following format: @Library('my-shared-library1') @Library('my-shared-library2@1.0') @Library('my-shared-library3@my-branch-name') I want to…
1
vote
0 answers

org.mockito.exceptions.misusing.WrongTypeOfReturnValue while stubbing a function from a "spy" object with mockito in groovy

I'm having this issue which has taken enough time from me so I decided to ask the experts here. Some context.. I have a Jenkins shared library which with some groovy classes and I'm writing some unit tests using the JenkinsPipelineUnit framework.…
1
vote
1 answer

Passing/Injecting/Referring Environment variables from Jenkins file to Shared Library which has the generic code

I have a common Jenkins shared library for all the repositories as below vars/_publish.groovy def call(opts) { pipeline { environment { abc= credentials(’abc') def= credentials(‘def’) } stages { …
1
vote
0 answers

Jenkins shared library: Failure in instantiating class via Builder pattern

CloudBees Core: 2.249.1.2-rolling The code here is residing in a Jenkins shared library, which in turn is called by other Jenkins shared libraries. Below is an implementation of a standard Builder pattern to create an instance of a custom…
1
vote
1 answer

Use multi-method global variables in Jenkins Shared Libraries

Consider this groovy file in a repo that is loaded as shared library in Jenkins: / vars | --- Utility.groovy // Utility.groovy def funcA() { ... } def funcB() { ... } And in the Jenkinsfile: // Jenkinsfile @Library('LibName') _ pipeline…
YoavKlein
  • 2,005
  • 9
  • 38
1
vote
1 answer

How do I get proper syntax highlighting in Eclipse when developing a shared library of Jenkins?

I'm in the process of developing a shared library for Jenkins with scripts in vars/ and classes in src/. I have these two stumbling blocks: I use a Jenkins-specific method sh or echo. It is greyed out because Eclipse doesn't recognize it as a…
1
vote
1 answer

How do I use sh in Jenkins Global library

I am creating my own global library for Jenkins, which I have hosted on github, and to simplify some run-of-the-mill tasks, I wanted to add a function that returns the GIT tag. Therefore I created something like this: class Myclass{ static…
JoSSte
  • 2,953
  • 6
  • 34
  • 54
1
vote
1 answer

Is it possible to convert a Jenkins Shared Library into a Jenkins plugin?

I have a Jenkins Shared Library which supports functions to checkout, build, etc. Is it possible to convert the entire library into a plugin making it more portable and also protect the code? Or any other ways by which I might not expose the code…
1
vote
2 answers

Optional dependencies of external library added via Grab not available

It is not possible to use external third party libaries with optional dependencies properly in shared libraries for Jenkins. I have a shared library which uses Commons Configurations 2 to read varios configuration files, mostly written as YAML…
Oliver
  • 3,815
  • 8
  • 35
  • 63
1
vote
1 answer

How to create withXCredentials that wraps Jenkins withCredentials using Closure in Jenkins shared variable?

I want to have this code with exactly this syntax in my pipeline script: withXCredentials(id: 'some-cred-id', usernameVar: 'USER', passwordVar: 'PASS') { //do some stuff with $USER and $PASS echo "${env.USER} - ${env.PASS}" } Note that you…
xbmono
  • 2,084
  • 2
  • 30
  • 50
1
vote
1 answer

Jenkins shared pipeline lib - get build status

I am trying to build a reusable library for a Jenkins pipeline project, but I can't seem to figure out how to get the build status as well as set it. If I use a Jenkinsfile or a vars script, it works, but what I'm interested in is using the src/…
Serban Cezar
  • 507
  • 1
  • 8
  • 19
1
vote
1 answer

Calling a Closure from jenkins-library inside job's pipeline

I have jenkins_library with handleCheckout.groovy which handles checkout: def handleCheckout = { if (env.gitlabMergeRequestId) { sh "echo 'Merge request detected. Merging...'" checkout([ $class :…