jenkins发布构建步骤和操作-有什么区别 [英] jenkins post build step and action - what is the difference

查看:70
本文介绍了jenkins发布构建步骤和操作-有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

听起来可能是一个非常基本的问题-但我找不到任何文章来解释为何詹金斯(Jenkins)提供了后期制作步骤以及操作.

在詹金斯(Jenkins)中,我确实看到在构建阶段步骤和操作过程中,选项是不同的,但是

  • 执行顺序是什么?
  • 我们什么时候应该使用哪个选项?
  • 最佳做法是什么?

解决方案

乍看之下,这是詹金斯的工作流程(没有其他插件)

  1. [根据需要,按需提供] .安装工具,(例如JDK,Ant,Maven等).
  2. [可选] 执行SCM结帐,(例如SVN或Git).
  3. 执行构建步骤,(例如构建Ant项目,编译代码等).
  4. [可选] ,执行构建后步骤,(例如,存档工件,发送电子邮件等).

有些插件可以在工具安装后立即执行操作,例如

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?

解决方案

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.

这篇关于jenkins发布构建步骤和操作-有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆