DEVOPS技术实践_08:声明式管道语法

简介

前面简单的做了管道的实验,看了一下的它的效果

声明式管道是Groovy语法中的一个更简单和结构化的语法。下面主要学习明式管道语法。

一 声明式管道的基本结构

以上节的代码为例

node {
   def mvnHome
   stage(‘Preparation‘) { // for display purposes
      // Get some code from a GitHub repository
      git ‘https://github.com/jglick/simple-maven-project-with-tests.git‘
      // Get the Maven tool.
      // ** NOTE: This ‘M3‘ Maven tool must be configured
      // **       in the global configuration.
      mvnHome = tool ‘M3‘
   }
   stage(‘Build‘) {
      // Run the maven build
      withEnv(["MVN_HOME=$mvnHome"]) {
         if (isUnix()) {
            sh ‘"$MVN_HOME/bin/mvn" -Dmaven.test.failure.ignore clean package‘
         } else {
            bat(/"%MVN_HOME%\bin\mvn" -Dmaven.test.failure.ignore clean package/)
         }
      }
   }
   stage(‘Results‘) {
      junit ‘**/target/surefire-reports/TEST-*.xml‘
      archiveArtifacts ‘target/*.jar‘
   }
}

1.1 node块

node块定义Jenkins agent,在node中定义了stage blocks, directives和steps.
node块的结构看起来如下所示:
node (‘‘) {}

下面给关于node块更详细的信息:

  • – Defines: stge,directives或者steps应该运行的节点。
  • – Constituents: 多个stage块、directives或steps.
  • – Required: Yes
  • – Parameters: Any, label

node (‘master’) { 这里的字符串master是一个参数,是告诉Jenkins去使用Jenkins master运行node里面的块内容。

如果是any的话,那就是所有的agnet的都可以去运行。

1.2 Stage块

stage块是一群相关对象的steps和directives的集合。stage块结构看起来如下所示:
stage (‘‘) {}

下面给出关于stage块的更详细信息。

  • Defines: 一组steps和directives.
  • Constituents: 多个node块、directives或者steps.
  • Required: Yes
  • Parameters: A string that is the name of the stage(mandatory)

1.3 Directives

指令的主要目标是给node block,stage block和 stage block提供以下元素:环境变量、选项、参数、触发器、工具。

下面给出了关于stage 块的更详细信息。

  • Defines: 这个阶段应该运行的节点位置(就是在哪个节点上运行)。
  • Constituents: Environments, options, parameters, triggers, tools
  • Required: No, but every CI/CD pipeline has it.
  • Parameters: None

1.4 Step

阶段是组成声明管道的基本元素。step可以是batch脚本或者shell脚本,或者其它任何可以执行的命令。 steps有多种多样的用处,比如刻隆代码,构建代码,运行测试,上传软件到repository server,执行静态代码分析等。 在上一章节,也看到了如何使用Jenkins管道语法工具。

下面给出了关于step块的更详细信息:

  • Defines: 它告诉Jenkins干什么
  • Constituents: 命令,脚本等。它也是管道的基本块。
  • Required: No, 但每个CI/CD管道都有它。
  • Parameters: None

二 jenkins语法管道工具

Jenkins pipeline syntax utility是快速简单的创建pipeline代码的方式。

下面学习使用pipeline syntax utility重新创建pipeline

2.1准备工作

安装一个插件

  • 在Global Tool Configuration页面中配置Maven tool.
  • 安装Pipleline Maven Integration Plugin.
  • 构建Maven项目时需要Java工具,因此此处构建时使用Jenkins master.

2.2 使用pipeline syntax utility 创建Jenkins pipeline.

新建任务,取名jenkins_pineline_demo_utility,使用流水线

点击流水线的流水线语法

界面显示

2.3 连接一个node

复制过来

2.4 创建两个stage块,名字分别为Preparation和Build,并复制脚本到第(3)步的编辑器中

复制过来

2.5 Build操作

复制过来

2.6 创建一个step去从GitHub服务器下载源码。并把产生的代码复制,放到Preparation 的stage块中

复制过来

2.7 产生指令告诉jenkins去使用我们先前在【全局工具配置】的M3 maven工具。,然后把代码复制到Build的stage块中

复制代码过来

2.8 针对Maven 构建命令产生一个pipeline的代码。然后把脚本内容复制到withMaven指令中去

复制代码

最终代码如下

node(‘master‘) {
    // some block
    stage(‘Preparation‘) {
    // some block
    //step
    git ‘https://github.com/jglick/simple-maven-project-with-tests.git‘
}
    stage(‘Build‘) {
    // some block
    //step
    withMaven(maven: ‘M3‘) {
    // some block
    sh label: ‘‘, script: ‘mvn -Dmaven.test.failuer.ignore clean package‘
}
}
}

保存,并构建

2.9 构建

构建失败

修改代码

node(‘master‘) {
    // some block
    stage(‘Preparation‘) {
    // some block
    //step
    git ‘https://github.com/jglick/simple-maven-project-with-tests.git‘
}
    stage(‘Build‘) {
    // some block
    //step
    withMaven(maven: ‘M3‘) {
    // some block
    sh label: ‘‘, script: ‘mvn -Dmaven.test.failuer.ignore clean install package‘
}
}
}

再次构建成功

2.10 构建结果

阶段视图

趋势图

控制台输出

Started by user darren ning
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /root/.jenkins/workspace/jenkins_pineline_demo_utility
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Preparation)
[Pipeline] git
No credentials specified
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/jglick/simple-maven-project-with-tests.git # timeout=10
Fetching upstream changes from https://github.com/jglick/simple-maven-project-with-tests.git
 > git --version # timeout=10
 > git fetch --tags --progress https://github.com/jglick/simple-maven-project-with-tests.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision b3a39b21ac048d9298986e0d4a1d9f4dd185df8f (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f b3a39b21ac048d9298986e0d4a1d9f4dd185df8f
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D master # timeout=10
 > git checkout -b master b3a39b21ac048d9298986e0d4a1d9f4dd185df8f
Commit message: "Merge pull request #13 from jglick/Jenkinsfile"
 > git rev-list --no-walk b3a39b21ac048d9298986e0d4a1d9f4dd185df8f # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] withMaven
[withMaven] Options: []
[withMaven] Available options:
[withMaven] using JDK installation provided by the build agent
[withMaven] using Maven installation ‘M3‘
[Pipeline] {
[Pipeline] sh
+ mvn -Dmaven.test.failuer.ignore clean install package
----- withMaven Wrapper script -----
Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path="/root/.jenkins/workspace/[email protected]/withMaven161c0da4/pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/root/.jenkins/workspace/[email protected]/withMaven161c0da4"
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T11:06:16-04:00)
Maven home: /root/.jenkins/tools/hudson.tasks.Maven_MavenInstallation/M3
Java version: 1.8.0_222, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.27.2.el7.x86_64", arch: "amd64", family: "unix"
[INFO] [jenkins-event-spy] Generate /root/.jenkins/workspace/[email protected]/withMaven161c0da4/maven-spy-20191026-094419-4317832432301871131598.log.tmp ...
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< test:simple-maven-project-with-tests >----------------
[INFO] Building simple-maven-project-with-tests 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom (6.4 kB at 2.3 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.jar (27 kB at 20 kB/s)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ simple-maven-project-with-tests ---
[INFO] Deleting /root/.jenkins/workspace/jenkins_pineline_demo_utility/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ simple-maven-project-with-tests ---
[INFO] Using ‘UTF-8‘ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/jenkins_pineline_demo_utility/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ simple-maven-project-with-tests ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ simple-maven-project-with-tests ---
[INFO] Using ‘UTF-8‘ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/jenkins_pineline_demo_utility/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ simple-maven-project-with-tests ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /root/.jenkins/workspace/jenkins_pineline_demo_utility/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ simple-maven-project-with-tests ---
[INFO] Surefire report directory: /root/.jenkins/workspace/jenkins_pineline_demo_utility/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path="/root/.jenkins/workspace/[email protected]/withMaven161c0da4/pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/root/.jenkins/workspace/[email protected]/withMaven161c0da4"
Running test.OtherTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec - in test.OtherTest
Running test.SomeTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec - in test.SomeTest

Results :

Tests run: 7, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ simple-maven-project-with-tests ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /root/.jenkins/workspace/jenkins_pineline_demo_utility/target/simple-maven-project-with-tests-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ simple-maven-project-with-tests ---
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom (2.5 kB at 3.2 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.1/plexus-3.1.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/3.1/plexus-3.1.pom (19 kB at 17 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom (1.1 kB at 1.5 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.7/plexus-components-1.1.7.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.7/plexus-components-1.1.7.pom (5.0 kB at 7.1 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.8/plexus-1.0.8.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.8/plexus-1.0.8.pom (7.2 kB at 9.4 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom (7.3 kB at 11 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.jar (12 kB at 6.6 kB/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar (230 kB at 83 kB/s)
[INFO] Installing /root/.jenkins/workspace/jenkins_pineline_demo_utility/target/simple-maven-project-with-tests-1.0-SNAPSHOT.jar to /root/.m2/repository/test/simple-maven-project-with-tests/1.0-SNAPSHOT/simple-maven-project-with-tests-1.0-SNAPSHOT.jar
[INFO] Installing /root/.jenkins/workspace/jenkins_pineline_demo_utility/pom.xml to /root/.m2/repository/test/simple-maven-project-with-tests/1.0-SNAPSHOT/simple-maven-project-with-tests-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ simple-maven-project-with-tests ---
[INFO] Using ‘UTF-8‘ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/jenkins_pineline_demo_utility/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ simple-maven-project-with-tests ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ simple-maven-project-with-tests ---
[INFO] Using ‘UTF-8‘ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/jenkins_pineline_demo_utility/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ simple-maven-project-with-tests ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ simple-maven-project-with-tests ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ simple-maven-project-with-tests ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  14.193 s
[INFO] Finished at: 2019-10-26T09:44:33-04:00
[INFO] ------------------------------------------------------------------------
[INFO] [jenkins-event-spy] Generated /root/.jenkins/workspace/[email protected]/withMaven161c0da4/maven-spy-20191026-094419-4317832432301871131598.log
[Pipeline] }
[withMaven] artifactsPublisher - Archive artifact pom.xml under test/simple-maven-project-with-tests/1.0-SNAPSHOT/simple-maven-project-with-tests-1.0-SNAPSHOT.pom
[withMaven] artifactsPublisher - Archive artifact target/simple-maven-project-with-tests-1.0-SNAPSHOT.jar under test/simple-maven-project-with-tests/1.0-SNAPSHOT/simple-maven-project-with-tests-1.0-SNAPSHOT.jar
[withMaven] junitPublisher - Archive test results for Maven artifact test:simple-maven-project-with-tests:jar:1.0-SNAPSHOT generated by maven-surefire-plugin:test (default-test): target/surefire-reports/*.xml
[withMaven] junitPublisher - Archive test results for Maven artifact test:simple-maven-project-with-tests:jar:1.0-SNAPSHOT generated by maven-surefire-plugin:test (default-test): target/surefire-reports/*.xml
[withMaven] junitPublisher - Jenkins JUnit Attachments Plugin not found, can‘t publish test attachments.Recording test results
[withMaven] Jenkins Task Scanner Plugin not found, don‘t display results of source code scanning for ‘TODO‘ and ‘FIXME‘ in pipeline screen.
[withMaven] Publishers: Pipeline Graph Publisher: 14 ms, Generated Artifacts Publisher: 23 ms, Junit Publisher: 13 ms, Open Task Scanner Publisher: 1 ms
[Pipeline] // withMaven
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

基本成功



参考文档:https://blog.xiodi.cn/2018/07/18/%e4%b8%89-jenkins%e7%9a%84%e6%96%b0%e5%8a%9f%e8%83%bd%e4%b9%8b%e4%b8%89-jenkins%e7%ae%a1%e9%81%93%e8%af%ad%e6%b3%95%e5%ae%9e%e7%94%a8%e7%a8%8b%e5%ba%8f/

原文地址:https://www.cnblogs.com/zyxnhr/p/11746974.html

时间: 2024-09-30 19:07:51

DEVOPS技术实践_08:声明式管道语法的相关文章

DEVOPS技术实践_08:Jenkins多分支管道

简介 多分支的管道是在jenkins2.x中新增的功能 . 多分支管道允许你针对分布式的控制器的每个分支创建一个管道. 下图是对它的一个描述.使用jenkinsfile去创建多分支的管道,jenkinsfile可以存放在代码仓库中. Jenkinsfile只是定义CI管道的一个脚本. 另外,多分支管道的设计初衷就是当Git仓库中的代码改变时,去自动触发构建.下图是对它的一个描述. 一. 准备工作 (1)在[全局工具配置]中Maven工具已经配置好.(2)安装了[Pipeline Maven In

DEVOPS技术实践_12:创建持续集成的管道

持续集成不仅包含了Jenkins或者相关其它的CI工具,也包含了包含代码如何控制,采用的什么分支策略等.不同的组织可能采用不同的类型的策略来完成CI,策略类型和项目的类型的有很大的关系. 一 分支策略 1.1 本实验分支 分支能够有效的对代码较好的管理,也是能够把工作的代码和开发环境的代码隔离的有效方式.主要有三种的分支策略类型– master分支– integration 分支– feature 分支 1.master分支 master分支也叫做生产分支,该分支的代码全部是经过测试OK的代码.

DEVOPS技术实践_13:使用Jenkins持续传送设计-CD基础

1. 分支策略 持续集成中使用的分支策略包括以下三个: The master branch The integration branch The feature branch 而CD只在Integration的release上分支上执行即可. 2. Release 分支 一些团队采用发布分支的策略.release分支是在所有代码在生产环境中经过验证之后创建的.也就是从master上面拉取的.创建release分支的目的就是在相应的版本上进行bug修复. 3. CD 管道 在此处,不会再创建新的p

DEVOPS技术实践_10:安装部署Artifactory

需要一种机制去存储所有的二进制代码(build,packages,third-party plugins等)到类似于版本控制系统的系统. 像Git,SVN存储代码,它们存储的往往是源代码,不是二进制文件.Artifactory或者Nexus就是和Jenkins紧密集成的二进制文件存储库系统. 可以带来以下好处:追踪构建(谁触发?谁构建)依赖关系部署历史 jfrog artifactory是一款二进制存储管理工具,用来管理构建工具(如:maven.gradle)等所依赖的二进制仓库,以方便管理第三

DEVOPS技术实践_11:Jenkins集成Sonar

前言 前面已经有介绍sonar的安装,简单应用,下面在简答的研究一下sonar和jenkins集成的简单使用,对于sonar的安装不做介绍 一 sonar的简单介绍 持续检查避免了低质量的代码,比如SonarQube工具就能够帮助我们完成此项.每次代码提交后,在代码上就会执行代码分析. 分析是基于代码分析工具中定义的一些规则,如果代码通过了错误阀值,那么它会允许到生命周期的下一步,如果超过了设定的阀值,那么直接返回错误. SonarQube是代码质量管理工具,允许团队去管理,追踪和改善他们的源代

Spring(四)-- JdbcTemplate、声明式事务

1.Spring提供的一个操作数据库的技术JdbcTemplate,是对Jdbc的封装.语法风格非常接近DBUtils. JdbcTemplate可以直接操作数据库,加快效率,而且学这个JdbcTemplate也是为声明式事务做准备,毕竟要对数据库中的数据进行操纵! JdbcTemplate中并没有提供一级缓存,以及类与类之间的关联关系!就像是spring提供的一个DBUtils. Spring对数据库的操作使用JdbcTemplate来封装JDBC,结合Spring的注入特性可以很方便的实现对

通过 React Hooks 声明式地使用 setInterval

本文由云+社区发表 作者:Dan Abramov 接触 React Hooks 一定时间的你,也许会碰到一个神奇的问题: setInterval 用起来没你想的简单. Ryan Florence 在他的推文里面说到: 不少朋友跟我提起,setInterval 和 hooks 一起用的时候,有种蛋蛋的忧伤. 老实说,这些朋友也不是胡扯.刚开始接触 Hooks 的时候,确实还挺让人疑惑的. 但我认为谈不上 Hooks 的毛病,而是 React 编程模型和 setInterval 之间的一种模式差异.

Jenkins教程——从安装到部署Docker服务(二)声明式流水线HelloWorld

前言 本文通过一个声明式流水线的HelloWorld程序做一下流水线基础入门,对常用的流水线参数进行简要说明 什么是流水线 现实中的流水线 流水线比较好理解,类比于现实生活中的生产流水线,每个流程只做一件事,通过传送带把这些流程连接在一起,一个流程完成后的结果交由后续流程继续操作. Jenkins的流水线简单认知 Jenkins的流水线也是这样工作的,最简单的认知是它可以把若干可通用的Shell脚本像胶水一样连接起来,虽然这个比喻比较形象,但这只是流水线的冰山一角. Jenkins流水线的两种形

spring 声明式事务管理

简单理解事务: 比如你去ATM机取1000块钱,大体有两个步骤:首先输入密码金额,银行卡扣掉1000元钱:然后ATM出1000元钱.这两个步骤必须是要么都执行要么都不执行.如果银行卡扣除了1000块但是ATM出钱失败的话,你将会损失1000元:如果银行卡扣钱失败但是ATM却出了1000块,那么银行将损失1000元.所以,如果一个步骤成功另一个步骤失败对双方都不是好事,如果不管哪一个步骤失败了以后,整个取钱过程都能回滚,也就是完全取消所有操作的话,这对双方都是极好的. 当这两个步骤提交了,执行完毕