There are 2 jobs, in them the same project; one job is started only when a new version of git is detected; The second job should run the latest version of git, whose build was successful in the 1st job.

How to make the 2nd job run the last successful build of the 1st job?

  • Periodically, I return to this question, the most interesting answer. - Nick Volynkin
  • The @NickVolynkin answer is simple - move to TimCity: D. I’ve been dealing with Jenkins lately - and I’m more and more aware of how cool the product was made by the Jetbrains. - andreycha
  • @andreycha we are thinking about GitLab CI, because we already use GitLab itself. - Nick Volynkin

3 answers 3

I'm not a big jenkins specialist, but I would do that. The first task to perform the compilation of the project, copies the compiled files needed for the program to a separate folder. Roughly speaking, she makes the installation.

The second task at startup checks the presence of files in the folder and launches it if there are any. Since the unsuccessful compilation of the project in the first case will not delete the compiled files from the special folder, the second task will always be able to run the “last successful build”.

  • it is even better if there is a prepared repository for builds (if the result is jars or docker containers) - in this case, everything becomes quite nice - etki

There are many ways. In the first project I would save GIT_COMMIT to a file ( echo GIT_COMMIT=$GIT_COMMIT > env.properties , and in the second project I would copy this file from the last successful build of the first project ( Copy artifact plugin) and use it in a shell script or import the information with a plugin EnvInject , which is safer.

And the big boys make an HTTP request to the API (URL like http://твой_сервер/job/твой_проект/lastStableBuild/api/json?tree=actions[lastBuiltRevision[branch[*]]] ) and analyze the resulting JSON

    In an ideal CI system, this scheme should work like this:

    • the first build builds and publishes the result (for example, binaries) as an artifact
    • The second build should depend on the first one: take its artifacts from the last successful first build and launch it either manually or automatically

    In TimCity, for example, this is all out of the box. As for Jenkins:

    • artifacts for the first build it generates
    • The Copy Artifacts plugin will help the second build to copy artifacts from the first build (and you need to specify what you need to take from Last successful build), and there are different ways to automatically launch the second build, including and embedded