0

I'd like to define build steps in a generic way by reading info from a Yaml/Json file.

Use case: Share information about build stages among different types of CI (i.e. I have lot's of build stages and want to implement those for different CIs and for local usage (as described here)

The problem I face now with Jenkins is that this file won't be available before checking out the whole project which is done in the first stage, i.e. I don't yet have the information about the stages I want to define when I need it.

Is there a solution for this situation? Can I select files to be provided among the main Jenkinsfile before running the actual stages?

frans
  • 8,868
  • 11
  • 58
  • 132
  • The default behaviour of most plugins is that they check out the Jenkinsfile and then the whole project. I don't see why you would want to generify a Jenkinsfile? It's already generic enough. If you have a complex Jenkinsfile, maybe you could extract logic into bash scripts or something else. Although I don't get your reasoning for using a YAML/JSON, depending on where you use them, the availability might differ. If you use them in the steps, it should be alright. – Vivere Apr 26 '21 at 11:09
  • 1
    I agree in general, but sometimes one cannot easily go back in time and choose a different approach in the first place. In my case we have Jenkinsfiles with lots of redundant code which even get's reproduced outside the Jenkinsfile to be able to "do what Jenkins does". My current goal is to put dozens of stage definitions out of the Jenkinsfile in order to also use this information outside of Jenkins. – frans Apr 26 '21 at 11:25
  • 1
    Btw. another reason why you might want to generalize build stages is if you use more than one kind CI but you have to somehow share the common logic. – frans Apr 26 '21 at 11:27
  • This sounds complex. What I suggest is having two jobs. In one, you could have a Jenkinsfile that only checkouts the SCM and starts another Job based on some config files. – Vivere Apr 26 '21 at 11:52
  • 1
    In the end I want stages of course. If there was no need for pipeline jobs I wouldn't have to define stages in a generic way. Strangely there _are_ ways to define stages dynamically (see https://stackoverflow.com/questions/42837066/can-i-create-dynamically-stages-in-a-jenkins-pipeline) - I wonder how they can be used without additional available files.. – frans Apr 26 '21 at 12:41
  • What you are asking is not possible, you need to have atleast dependency jobs to get a fresh set of files. On the other hand, you can try out multi branch pipelines, and have different branches of the pipelines do different activities and can communicate with each other inside your build environment too. – mdabdullah Apr 26 '21 at 13:37

0 Answers0