Is there an easy way to configure post build actions for Jenkins jobs via code?

gabriel.nemeth987
gabriel.nemeth987 Spryker Solution Partner Posts: 5 🧑🏻‍🚀 - Cadet

Without a way for doing so, any such actions need to be set up manually again after each instance restart/regeneration. It would be nice if this chore could be avoided.

As I see, this is not possible via the jenkins php file, although that would be the simplest. Or am I missing something…? (I hope, otherwise custom building will be the only option remaining…)

Answers

  • mikko.ropanen
    mikko.ropanen Spryker Solution Partner Posts: 31 ✨ - Novice

    You can extend/override vendor/spryker/scheduler-jenkins/src/Spryker/Zed/SchedulerJenkins/Business/TemplateGenerator/Template/jenkins-job.default.xml.twig

    Depending on what you're hoping to accomplish, this may or may not work for you :)

  • gabriel.nemeth987
    gabriel.nemeth987 Spryker Solution Partner Posts: 5 🧑🏻‍🚀 - Cadet

    Yep, looking at it just now, trying to find out the syntax for specifying the post build action there. Do you have any info about that, perhaps?

    (I'm simply trying to chain jobs - one should start another once it's through, even if it fails.)

  • mikko.ropanen
    mikko.ropanen Spryker Solution Partner Posts: 31 ✨ - Novice

    I did some studying before the summer holidays. Basically you can experiment in the Jenkins UI and then check the resulting job XML from e.g. http://scheduler.spryker.local/job/FI_queue-worker-start/config.xml

    It is also technically possible to change the "free-style" default job template to a more flexible "pipeline" type job (which makes it easier to chain jobs and handle failures), but that makes Jenkins run out of memory real fast.

  • gabriel.nemeth987
    gabriel.nemeth987 Spryker Solution Partner Posts: 5 🧑🏻‍🚀 - Cadet

    Yep, looking at the xml is what I ended up doing too (although the in-browser URL approach didn't work for me, had to use the cli), that's how I found that this is what it should look like:

    <publishers>
        <hudson.tasks.BuildTrigger>
            <childProjects>{name of project to build}</childProjects>
                <threshold>
                <name>FAILURE</name>
                <ordinal>2</ordinal>
                <color>RED</color>
                <completeBuild>true</completeBuild>
            </threshold>
        </hudson.tasks.BuildTrigger>
    </publishers>