0

Situation: I have a Jenkins pipeline job file with lots of (regularly changing) stages hard-coded with Groovy and I need a way to locally reproduce, what being done on CI.

In order to let the developer locally do, "what Jenkins would do" without having to manually keep a list of steps synchronized with the respective Jenkinsfile I'm looking for a way to store the ordered list of stages accessible by both Jenkins and a local script.

In other words - I want to be able to check out my project repository and run

make what-Jenkins-would-do

(make is only an example - I really don't want to use make for this)

So, given a set of scripts which contain what's being executed on each stage I now just need the order of execution stored in a sophisticated way.

What I'd love to have is a way to let Jenkins read a list of pipeline steps from a Yaml/JSON file which then can be used in other scripts, too.

Here is what's going through my mind

  • I can't be the only one - there must be a tiny nice solution for this need
  • maybe I could use Groovy locally, but that would add another heavy dependency to my project and the Groovy-scripts contain lot's of Jenkins- and node-specific stuff I don't need locally
  • Don't want to store information redundantly
  • Just executing a 'do it all' script in both Jenkins and locally is not an option of course - I need individual stages.
  • Jenkins / Groovy and pipeline jobs are a requirement - I can't change that

So what's the modern solution to this? Is there something like

node('main') {
    stage('checkout') {
        // make the source code available
    }
    stages_from_file("build-stages.yaml")
}

?

frans
  • 8,868
  • 11
  • 58
  • 132
  • 1
    You can run the Jenkinsfile from the command-line using jenkinsfile-runner https://github.com/jenkinsci/jenkinsfile-runner – Szymon Stepniak Apr 22 '21 at 06:14
  • I'll definitively have a closer look at this project as it seems to target what I want to achieve. On the other hand `jenkinsfile-runner` introduces Java as a dependency, what I'd like to avoid. – frans Apr 22 '21 at 06:22
  • There is a docker image you can use to execute the Jenkinsfile inside the container. No dependencies other than docker needed. – Szymon Stepniak Apr 22 '21 at 06:27

0 Answers0