Declarative pipeline - Call another Jenkinsfile from pipeline script

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Declarative pipeline - Call another Jenkinsfile from pipeline script

Ashish Sharma-2
Dear All,

Below is our usecase (using declarative script):
  • We have a small pipeline script (Jenkinsfile) which will do sanity, tests & lint check on every feature branch and pull requests
  • Then we have another script (Jenkinsfile) which is superset which will additionally build and deploy as well. We will use this for develop / master branches
  • We are planning to use Org folders (BitBucket teams) to scan repo and create pipeline automatically.

How can we reuse our first script file to be included in second script, so that we don't have to duplicate declarative script?

Any other suggestions on how you generally tackle such cases?

Thanks,
Ashish

--
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/3c04e466-c858-444d-a0cc-923cc57f0469n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Declarative pipeline - Call another Jenkinsfile from pipeline script

Saravanan Manickam
I am not sure whether I understood completely..  you could have used "when" condition to match the branch and do all the additional steps you want.  It'll be clean that way.

Regards,
Saravanan

On Tuesday, September 8, 2020 at 7:27:50 AM UTC+5:30 [hidden email] wrote:
Dear All,

Below is our usecase (using declarative script):
  • We have a small pipeline script (Jenkinsfile) which will do sanity, tests & lint check on every feature branch and pull requests
  • Then we have another script (Jenkinsfile) which is superset which will additionally build and deploy as well. We will use this for develop / master branches
  • We are planning to use Org folders (BitBucket teams) to scan repo and create pipeline automatically.

How can we reuse our first script file to be included in second script, so that we don't have to duplicate declarative script?

Any other suggestions on how you generally tackle such cases?

Thanks,
Ashish

--
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/1ff7b13b-75b4-440b-abbb-e106ed56ec16n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Declarative pipeline - Call another Jenkinsfile from pipeline script

Gianluca

I agree with Saravanan ... and I would also add that there are other two Jenkins features we use for your case.
The approach we follow is:
- first we try with "when" to run stages conditionally depending on branches/parameters/tags/directory and so on
- when we see many times the same piece of code and we want to DRY, then we use the readTrusted to load a snippet of functionality:
def notifier = evaluate readTrusted('./scripts/jenkins/notifier.groovy')
- when we see many times the same piece of code used across different repositories, then we use the Library approach:
@Library('osirium-pipelines@2.0.1')_



Il giorno mar 8 set 2020 alle ore 16:09 Saravanan Manickam <[hidden email]> ha scritto:
I am not sure whether I understood completely..  you could have used "when" condition to match the branch and do all the additional steps you want.  It'll be clean that way.

Regards,
Saravanan

On Tuesday, September 8, 2020 at 7:27:50 AM UTC+5:30 [hidden email] wrote:
Dear All,

Below is our usecase (using declarative script):
  • We have a small pipeline script (Jenkinsfile) which will do sanity, tests & lint check on every feature branch and pull requests
  • Then we have another script (Jenkinsfile) which is superset which will additionally build and deploy as well. We will use this for develop / master branches
  • We are planning to use Org folders (BitBucket teams) to scan repo and create pipeline automatically.

How can we reuse our first script file to be included in second script, so that we don't have to duplicate declarative script?

Any other suggestions on how you generally tackle such cases?

Thanks,
Ashish

--
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/1ff7b13b-75b4-440b-abbb-e106ed56ec16n%40googlegroups.com.

--
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/CAPddqDUG9%3DEJDj%3DrvT3UGhUo_np85BjNY70kpPdhf%3DaS8KwrBQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Declarative pipeline - Call another Jenkinsfile from pipeline script

Ashish Sharma-2
Thanks both, let us explore the suggested options. 
Stay safe. Cheers.

On Tue, 8 Sep 2020 at 11:19 PM, Gian Maxera <[hidden email]> wrote:

I agree with Saravanan ... and I would also add that there are other two Jenkins features we use for your case.
The approach we follow is:
- first we try with "when" to run stages conditionally depending on branches/parameters/tags/directory and so on
- when we see many times the same piece of code and we want to DRY, then we use the readTrusted to load a snippet of functionality:
def notifier = evaluate readTrusted('./scripts/jenkins/notifier.groovy')
- when we see many times the same piece of code used across different repositories, then we use the Library approach:
@Library('osirium-pipelines@2.0.1')_



Il giorno mar 8 set 2020 alle ore 16:09 Saravanan Manickam <[hidden email]> ha scritto:
I am not sure whether I understood completely..  you could have used "when" condition to match the branch and do all the additional steps you want.  It'll be clean that way.

Regards,
Saravanan

On Tuesday, September 8, 2020 at 7:27:50 AM UTC+5:30 [hidden email] wrote:
Dear All,

Below is our usecase (using declarative script):
  • We have a small pipeline script (Jenkinsfile) which will do sanity, tests & lint check on every feature branch and pull requests
  • Then we have another script (Jenkinsfile) which is superset which will additionally build and deploy as well. We will use this for develop / master branches
  • We are planning to use Org folders (BitBucket teams) to scan repo and create pipeline automatically.

How can we reuse our first script file to be included in second script, so that we don't have to duplicate declarative script?

Any other suggestions on how you generally tackle such cases?

Thanks,
Ashish








--


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/1ff7b13b-75b4-440b-abbb-e106ed56ec16n%40googlegroups.com.










--


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/CAPddqDUG9%3DEJDj%3DrvT3UGhUo_np85BjNY70kpPdhf%3DaS8KwrBQ%40mail.gmail.com.


--
Thanks,
Ashish

--
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/CAJd3NVs0YQAHNSYiFg1NcVws-eRt%2BYaX%2BZonZvJUw4KVu2-Riw%40mail.gmail.com.