# Better pipeline development workflow?

**URL:** <https://community.jenkins.io/t/better-pipeline-development-workflow/393>\
**Category:** Ask a question\
**Created:** [September 10, 2021, 5:39pm UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393 "2021-09-10T17:39:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jesusa](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/jesusa/32/327_2.png) [@jesusa](https://community.jenkins.io/u/jesusa)\
**Post date:** [September 10, 2021, 5:39pm UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393/1 "2021-09-10T17:39:45Z")

</div>

Hi all,

I have been using jenkins pipeline for years now and was wondering if there is anything better than my current workflow. When I start a new pipeline,

1. Create the jobs dsl groovy with the parameters to the pipeline  
declarative does not parse the parameters correctly for new pipelines.
2. Commit, push, run seed jobs
3. Edit pipeline library to create new step or helper functions
4. Edit jenkinsfile in Vim/Neovim to use new functions or debug print
5. commit push pipeline lib, pipeline, and any other dependent git repos
6. ssh to controller and run job, read output
  1. Fix syntax errors and typos

7. Repeat last 4 steps over and over.

Basically, is there a way to edit pipeline and pipelines library and test without having to commit to source control and push? Things would go so much smother if I didn’t have to wait around for git network operations. In a busy shop like my work, network can get slow sometimes.

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [September 10, 2021, 5:52pm UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393/2 "2021-09-10T17:52:48Z")

</div>

I don’t have a lot of suggestions, but

there’s lots of shell scripts out there that hit the linter api endpoint. It only works with declarative though - [GitHub - PeterMosmans/jenkinslint: Basic linter (validator) for Jenkinsfiles. Can easily be used in pre-commit hooks and the pre-commit framework](https://github.com/PeterMosmans/jenkinslint) looks like a decently robust version

For shared pipelines, you could use [GitHub - jenkinsci/JenkinsPipelineUnit: Framework for unit testing Jenkins pipelines](https://github.com/jenkinsci/JenkinsPipelineUnit) to confirm your shared libs work, then update a tag which all your jobs point to.

For small edits, there’s a link on the sidebar for replaying job, which lets you edit the pipeline script. lets you do quick edits that are not committed.

---

<div class="post-metadata">

**Author:** ![timja](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/timja/32/7_2.png) [@timja](https://community.jenkins.io/u/timja)\
**Post date:** [September 11, 2021, 6:56am UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393/3 "2021-09-11T06:56:00Z")

</div>

This plugin allows you to configure your shared library to be a directory instead of a SCM:

> **[File System SCM](https://plugins.jenkins.io/filesystem_scm/)**
>
> File System SCM

Good for iterating on a shared library

---

<div class="post-metadata">

**Author:** ![MadsJakobsen](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/madsjakobsen/32/129_2.png) [@MadsJakobsen](https://community.jenkins.io/u/MadsJakobsen)\
**Post date:** [September 11, 2021, 7:19pm UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393/4 "2021-09-11T19:19:32Z")

</div>

I second [GitHub - jenkinsci/JenkinsPipelineUnit: Framework for unit testing Jenkins pipelines](https://github.com/jenkinsci/JenkinsPipelineUnit) it can really help speed up development! You may also have side effects in your pipeline which you are not interested in when developing, so mocking them and being able to assert the method calls is super helpful and it’s great for catching regressions. It has saved me many, many, many hours 👍 Keep in mind you may not always get parity between JenkinsPipelineUnit and Jenkins due to [GitHub - jenkinsci/JenkinsPipelineUnit: Framework for unit testing Jenkins pipelines](https://github.com/jenkinsci/JenkinsPipelineUnit#note-on-cps).

Using [GitHub - jenkinsci/jenkinsfile-runner: A command line tool to run Jenkinsfile as a function](https://github.com/jenkinsci/jenkinsfile-runner) with File System SCM can also help speed up development, and get you closer to the final environment. I often use jenkinsfile-runner for testing jobDSL, to avoid new jobs on the controller when testing. For unit testing jobDSL it, I found this example helpful to get started [job-dsl-gradle-example/src/test/groovy/com/dslexample/builder at master · sheehan/job-dsl-gradle-example · GitHub](https://github.com/sheehan/job-dsl-gradle-example/tree/master/src/test/groovy/com/dslexample/builder)

Last advice when using jenkinsfile-runner (this is explicitly warned against in [Pipeline Best Practices](https://www.jenkins.io/doc/book/pipeline/pipeline-best-practices/#do-not-override-built-in-pipeline-steps)) is to override built-in steps in another library which is loaded along side the library which is being tested, I do this sometimes to mock `sh` or plugin steps. It’s brittle, It’s hard to maintain, but I found it helpful on occasions, and it was good to get off my chest 😛

---

<div class="post-metadata">

**Author:** ![shadycuz](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/shadycuz/32/196_2.png) [@shadycuz](https://community.jenkins.io/u/shadycuz)\
**Post date:** [September 15, 2021, 8:23am UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393/5 "2021-09-15T08:23:49Z")

</div>

This looks interesting, I do the same thing but in a shell script lol.

When developing locally:

```auto
def lib
node(){
    
    stage('Setup Dynamic Library'){
        sh(
            """\
            rm -rf lib || true && \
            mkdir lib || true && \
            cp -r /var/jenkins_home/shared_lib/* lib
            """
        )
        
        sh("""git config --global user.email "shadycuz@xxx.com" && \
                git config --global user.name "shadycuz"
        """)
        
        String repoPath = sh(returnStdout: true, script: 'pwd').trim() + "/lib"
        
        sh("""cd lib && \
                (rm -rf .git || true) && \
                git init && \
                git add --all && \
                git commit -m init
        """)
        lib = library identifier: 'local-lib@master', 
                retriever: modernSCM([$class: 'GitSCMSource', remote: repoPath]), 
                changelog: false
    }
    
    env.PIPELINE_LOG_LEVEL = 'DEBUG'
    
    String cps = sh(script: '#!/bin/bash\nset +x; > /dev/null 2>&1\necho Test for CPS issue', returnStdout: true)
    
    sh('mkdir -p images/ubuntu')
    
    def path = lib.org.dsty.os.Path.new("${env.WORKSPACE}/images")
}

```

In CICD I use a groovy init file:

```auto
/* groovylint-disable , FileCreateTempFile, JavaIoPackageAccess */
import jenkins.plugins.git.GitSCMSource
import org.jenkinsci.plugins.workflow.libs.GlobalLibraries
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration
import org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever

println('== Configuring the Jenkins Pipeline library')

final String libName = 'jenkins-std-lib'
final String repoBranch = 'master'
final LibraryConfiguration lc
final File file = new File('/var/jenkins_home/pipeline-library/src')

if (file.exists()) {
    println("===== Adding local ${libName}")

    StringBuilder stdout = new StringBuilder()
    StringBuilder stderr = new StringBuilder()

    File script = File.createTempFile('temp', '.sh')

    String lib = '/var/jenkins_home/lib'

    script.write(
        """#!/usr/bin/env bash
        mkdir ${lib} || true
        cp -r /var/jenkins_home/pipeline-library/* ${lib}

        git config --global user.email ""admin@non.existent.email""
        git config --global user.name "Jenkinsfile-runner"

        cd ${lib}
        rm -rf .git || true
        git init
        git add --all
        git commit -m init
        """
    )

    Process proc = "bash ${script.absolutePath}".execute()

    proc.consumeProcessOutput(stdout, stderr)
    proc.waitForOrKill(5000)

    if (stderr) {
        println("stdout: ${stdout}")
        println("stderr: ${stderr}")
    }

    GitSCMSource scm = new GitSCMSource(libName, lib, null, null, null, false)

    lc = new LibraryConfiguration(libName, new SCMSourceRetriever(scm))
    lc.with {
        implicit = true
        defaultVersion = repoBranch
    }
} else {
    println("===== Adding remote ${libName}")

    // TODO: change defaults once https://github.com/jenkins-infra/pipeline-library/pull/78 is merged
    String repoURL = 'https://github.com/DontShaveTheYak/jenkins-std-lib'

    println("===== Using the Pipeline library from ${repoURL}")

    GitSCMSource libSource = new GitSCMSource(libName, "${repoURL}.git", null, null, null, false)

    lc = new LibraryConfiguration(libName, new SCMSourceRetriever(libSource))
}

lc.with {
    implicit = true
    defaultVersion = repoBranch
}
GlobalLibraries.get().libraries.add(lc)

```

I might try out the File SCM plugin and see how it works, but I mostly happy with the setup I have.

---

<div class="post-metadata">

**Author:** ![shadycuz](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/shadycuz/32/196_2.png) [@shadycuz](https://community.jenkins.io/u/shadycuz)\
**Post date:** [September 15, 2021, 8:28am UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393/6 "2021-09-15T08:28:32Z")

</div>

Do you have an example of configuring `File System SCM` on a `jenkinsfile-runner`? This is my current setup [jenkins-std-lib/docker at master · DontShaveTheYak/jenkins-std-lib · GitHub](https://github.com/DontShaveTheYak/jenkins-std-lib/tree/master/docker)

---

<div class="post-metadata">

**Author:** ![shadycuz](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/shadycuz/32/196_2.png) [@shadycuz](https://community.jenkins.io/u/shadycuz)\
**Post date:** [September 15, 2021, 9:45am UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393/7 "2021-09-15T09:45:20Z")

</div>

Lots of people have already dropped some valuable knowledge in this thread, but let me give some of my highly opinionated and often controversial opinions.

> [@jesusa](#):
>
> Create the jobs dsl groovy with the parameters to the pipeline  
> declarative does not parse the parameters correctly for new pipelines.

I try not to use parameters at all and lots of them to me is a code smell. This is going to depend a lot on the type of jobs you have, but for IasC or CasC, the only parameter I typically have is log level. Most other CI tools like GitHub Actions, GitLab CI, Travis etc, don’t have parameters.

> [@jesusa](#):
>
> Commit, push, run seed jobs

For local development I often just hit replay over and over again. Sometime using my IDE and sometime just using the web interface on a local docker jenkins.

Most of the stuff I do involves infra, so I can’t even test locally, I just use our production jenkins and do the replay game.

For our jenkins-job repo we have automation that merges the feature branch with the main branch and then seeds it. It works okay for one person, but the second someone else comes along it wipes their job out. I have been meaning to make it merge all feature branches and seed that, but its low priority.

> [@jesusa](#):
>
> - Edit pipeline library to create new step or helper functions
> - Edit jenkinsfile in Vim/Neovim to use new functions or debug print

Mad respect to the wizards that still use vi and vim. If you want a little more help, like intellisense and auto-completion, you can try out vscode and the [Jenkins Extension Pack - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=DontShaveTheYak.jenkins-extension-pack).

> [@jesusa](#):
>
> - ssh to controller and run job, read output
> 
> 1. Fix syntax errors and typos
> 
> - Repeat last 4 steps over and over.

This is where the IDE comes in. I don’t have this problem anymore.

Lots of people mentioned the JenkinsFile-Runner and I also use it. My library is opensource if you want to see how I have it setup [GitHub - DontShaveTheYak/jenkins-std-lib: Bringing the Zen of Python to Jenkins.](https://github.com/DontShaveTheYak/jenkins-std-lib)

---

<div class="post-metadata">

**Author:** ![MadsJakobsen](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/madsjakobsen/32/129_2.png) [@MadsJakobsen](https://community.jenkins.io/u/MadsJakobsen)\
**Post date:** [September 16, 2021, 8:18pm UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393/8 "2021-09-16T20:18:32Z")

</div>

I made this one for it: [GitHub - MadsJakobsen/jenkinsfile-runner-filescm-example: Example of using filescm with jenkinsfile-runner](https://github.com/MadsJakobsen/jenkinsfile-runner-filescm-example)

---

<div class="post-metadata">

**Author:** ![shadycuz](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/shadycuz/32/196_2.png) [@shadycuz](https://community.jenkins.io/u/shadycuz)\
**Post date:** [September 16, 2021, 8:35pm UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393/9 "2021-09-16T20:35:02Z")

</div>

This is pretty slick. What about on a normal Jenkins? My main development Jenkins is a docker container, I only use runner for CICD.

If I configure my Jenkins container for file SCM, do I need to restart the container when I modify my library code, or will the changes take affect next time I run a job?

---

<div class="post-metadata">

**Author:** ![timja](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/timja/32/7_2.png) [@timja](https://community.jenkins.io/u/timja)\
**Post date:** [September 16, 2021, 9:18pm UTC](https://community.jenkins.io/t/better-pipeline-development-workflow/393/10 "2021-09-16T21:18:47Z")

</div>

You don’t need to restart the container assuming you’ve mounted it into your container
