Declarative Shared Library - Adding stages from outside

16 views
Skip to first unread message

Gavin Mogan

unread,
May 18, 2020, 12:18:42 AM5/18/20
to Jenkins Users
Hey Everyone,


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
Reply all
Reply to author
Forward
0 new messages