Questions tagged [jenkins-pipeline-unit]

Jenkins Pipeline unit testing framework

Jenkins Pipeline unit testing framework

https://github.com/jenkinsci/JenkinsPipelineUnit

20 questions
6
votes
0 answers

mocking custom steps in jenkins vars files

In my Jenkins shared library, I have tons of groovy files in the /vars dir that define custom steps. Many of them have multiple methods defined, and one method in a file may call another in the same file. I am looking for a way to mock these local…
Max Cascone
  • 648
  • 9
  • 25
5
votes
1 answer

How to mock a custom step using JenkinsPipelineUnit?

I'm using JenkinsPipelineUnit to test a pipeline. I define a custom step, like so: // vars/getOnlineNodes.groovy import jenkins.model.Jenkins def call() { Jenkins.get().nodes .findAll { it.toComputer().isOnline() } …
FuzzY
  • 660
  • 8
  • 23
4
votes
3 answers

Mocking findFiles in JenkinsPipelineUnit

Currently I'm trying to register findFiles step. My set up is as follows: src/ test/ groovy/ TestJavaLib.groovy vars/ javaLib.groovy javaApp.jenkinsfile Inside TestJavaApp.groovy I have: ... import…
4
votes
1 answer

How to use shared libraries with JenkinsPipelineUnit from current branch

I'm trying to use jenkinsPipelineUnit to test a JenkinsFile that exists in the same git repository as my shared libraries. This Jenkinsfile references shared libraries located in src. It appears that I must commit my shared library changes before I…
Damon
  • 305
  • 1
  • 5
  • 13
2
votes
0 answers

Using JenkinsPipelineUnit to test pipeline is returning error with import in the script

The pipeline I'm trying to execute with JenkinsPipelineUnit have some imports and full path classes. import org.jenkins.plugins.lockableresources.LockableResourcesManager (...) } catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException…
Paulo Oliveira
  • 2,411
  • 1
  • 31
  • 47
2
votes
0 answers

Unable to test BaselinePipelineTest withCredentialInterceptor

I'm trying to test a function in my Jenkins Script Pipeline. void doSomeDockerThings(){ withCredentials([[$class: 'UsernamePasswordMultiBinding', creditialsId: 'my_creds', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) { sh…
2
votes
1 answer

generate code coverage on JenkinsPipelineUnit tests

I am building a jenkins shared library (in groovy) and testing this with JenkinsPipelineUnit and in gradle. Running ./gradlew test jacocoTestReport runs fine, but the report is almost empty (just headers); no coverage is present. Here are the…
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
1
vote
0 answers

Jenkins shared library unit tests - missing dependencies and assert singleton values

I'm trying to write unit test to my Jenkins shared library using jenkins-pipeline-unit but for no success. My project/directory structure is: src/ └── org └── company ├── JobData.groovy ├── Constants.groovy ├──…
1
vote
2 answers

How to mock `pwsh` with libraryResource in Jenkins PipelineUnit

I am trying to write unit tests for the custom steps in my Jenkins Shared Library. I've landed on using Gradle and JenkinsPipelineUnit (via the articles linked at the end of this post), and I am getting stuck on mocking the pwsh step that runs a…
Max Cascone
  • 648
  • 9
  • 25
1
vote
1 answer

How to extract first 3 characters of jenkinsfile parameter

I need to extract the first 3 characters of jenkinsfile parameter: string(name: 'DB_Type', defaultValue: 'mysql' ) I tried the following but this did not work: prefix=${params.db_type} prefix=prefix.substring(0,2)
user312307
  • 153
  • 6
  • 21
1
vote
1 answer

Jenkins Pipeline Choose Specific Branch but take from default(master) branch

I have a Jenkins Pipeline that I would like to have a user input on to checkout a specific branch of their choosing. i.e. If I create a branch 'dev' and commit it in git,but Jenkins take a default branch(master) Can any one please help me take a…
Madhu BK
  • 27
  • 7
1
vote
2 answers

JenkinsPipelineUnit mock RunWrapper for shared library

I've written Jenkins shared library with helpers contained code like def foo() { ... return steps.build(job: jobName, wait: true, propagate: true, parameters: parameters) } class RunConfig implements Serializable { ... RunWrapper…
AlexMakarov
  • 108
  • 1
  • 8
1
vote
2 answers

How to test Jenkinsfiles with JenkinsPipelineUnit under Maven

I am pretty new with using Jenkins pipelines and want to test my Jenkinsfiles and libraries. I found the JenkinsPipelinUnit but i am not able to let my tests running. I am building a microservice with Maven and added the dependency for…
1
vote
0 answers

Mocking a Groovy Script object with stubbed methods with Spock?

What I'm trying to do I have a script that looks something like this: def doStuff() { println 'stuff done' } return this I am loading this script in another script so that I have a Groovy Script object that I can call doStuff from. This is in…
0
votes
0 answers

Jenkins unit test framework Assertion failed

I have this Jenkins Unit Test folder structure: enter image description here Code looks like this: package com.db import com.lesfurets.jenkins.unit.BasePipelineTest import org.junit.Before import org.junit.Test class TestExample extends…
1
2