Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

jenkins post build step and action - what is the difference

Might sound like a very basic question - but I am unable to find any article which explains why Jenkins provides a post build step as well as action.

In Jenkins - I do see that the options are different in post build step vs. action, but

  • what is the order of execution?
  • When should we use which option?
  • What are the best practices?
question from:https://stackoverflow.com/questions/26627975/jenkins-post-build-step-and-action-what-is-the-difference

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

At a glance, here is Jenkins' job workflow (without additional plugins)

  1. [On demand, if needed] Install tools, (such as JDK, Ant, Maven, etc).
  2. [Optional] Perform SCM checkout, (such as SVN or Git).
  3. Perform build step(s), (such as build Ant project, compile code, etc).
  4. [Optional] Perform post-build steps(s), (such as Archive Artifacts, send email, etc).

There are plugins that allow to perform actions right after Tools installation, such as Pre-SCM-step and EnvInject plugins. There are also plugins that add a lot more possible Build Steps and Post-build steps.

The difference between Build and Post-build steps is based partially on logical separation, partially on workflow configuration.

From the logical perspective, when you build/compile a project, that's a "Build" step, whereas when you Archive Artifacts, since that happens after the build, that's a "Post-build" step.

But there is also workflow configuration considerations, and it has everything to do with:

  • "When do the the builds fail", and with
  • "Build Status" (such as Success, Unstable, Failed)

When there are multiple "Build" steps, Jenkins:

  • Executes the first build step
  • Checks for exit code of the first build step
    1. If exit code is 0 (success), Jenkins continues to next build step (if there is one)
    2. If exit code is not 0 (failure), Jenkins marks build as FAILED, and continues to Post-build actions.
  • Jenkins executes Post-build steps (regardless if build was marked FAILED or not)

So, in other words:

  • If Build step succeeds, Jenkins can execute the following Build steps (if any).
  • If Build step fails, Jenkins will not execute the following Build steps.
  • If all Build steps succeeded, Jenkins will mark build SUCCESS.
  • If any Build step failed, Jenkins will mark build FAILED.
  • Post-build steps are executed regardless of Build Status (FAILED or not).

Technically, all post-build steps should be executed at all times, however in practice, if a Post-build step exceptions, the job never completes which can lead to some Post-build steps not being executed.

Also, generally Post-build steps do not change the Build Status, but there are some that are specifically designed to do that (for example, when Archiving Artifacts, you can choose to mark build FAILED if not all artifacts are found, even if after all Build steps, the build was marked SUCCESS)

So, knowing the above, it's your responsibility to design your job, and decide what steps need to be executed one after another, only if previous was successful, and will affect the Build Status (i.e. Build steps), and what steps need to happen at all times regardless of result (i.e Post-build steps).

EDIT:

Since I keep getting comments, here is a screenshot of a brand new clean installation of Jenkins (Windows) ver.1.634 (as was mentioned in comments).

On the screenshot, note the following:

  • New Freestyle project.
  • Scrollbar all the way down, there is nothing more on page.
  • Version 1.634 (as requested).
  • Build section with Add build step drop down.
  • Post-build Actions section with Add post-build action drop down.

So, to re-iterate my previous comment:

There is only one post-build "anything"

whether you want to call it "step" or "action" (Jenkins changed the labeling over the years).

Custom plugins can add a lot of extras, but for a clean install a basic job is just as I have described.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...