Declarative Shared Library - Adding stages from outside

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Declarative Shared Library - Adding stages from outside

Gavin Mogan
Hey Everyone,

I have a nice shared library pipeline that does a nice standard docker build - https://github.com/halkeye/jenkins-shared-library/blob/fe3da2b9519e91d7dbcf9a5584aceb52a0b627be/vars/buildDockerfile.groovy

This has worked great for the various pure docker projects I work on.

I'm looking to expand the library so I could do some before/after steps, which really just include running tests and calling junit(). I'm looking to do it in a nice declarative way though.

So far I came up with passing in a Closure, and calling it as needed inside scripts {} section

```
stage("Extra Steps") {
        steps {
          script {
            if (body) {
              body()
            }
          }
        }
      }
```

Buuut, that limits what I can do, I can't have more stages, just simple actions in one big blob. Its not unusable, but undesireable. I did find https://groups.google.com/forum/#!searchin/jenkinsci-users/closure$20declarative|sort:date/jenkinsci-users/E-3O1rHWkdM/SELjMGWLAwAJ but it sorta goes down the same path.

Is there a way to merge in an external jenkinsfile? maybe a load or something? Ideally I'd like to just have body() or something being called instead of stage so I can just add whatever I want.

Anyone have any ideas/solutions?

Gavin

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/9447275b-6c12-49db-9b50-162033eeba0e%40googlegroups.com.