仅在从git存储库中提取更改时运行构建任务

use*_*735 23 git ansible

我在Bitbucket git存储库中托管了一个C++程序,我正在使用CMake进行编译.目前的比赛可以在下面看到.它工作正常,除了build每次运行游戏时都运行-task.相反,我想 - build只有在git -module 提取新软件版本时才能运行.build如果clone--task找到新版本,我怎么能告诉-task ?

---
# tasks of role: foo

- name: clone repository
  git: repo=git@bitbucket.org:foo/foo.git
       dest={{ foo.dir }}
       accept_hostkey=yes

- name: create build dir
  file: state=directory path={{ foo.build_dir }}

- name: build
  command: "{{ item }} chdir={{ foo.build_dir }}"
  with_items:
    - cmake ..
    - make
Run Code Online (Sandbox Code Playgroud)

ghl*_*ogh 37

您可以在clone任务输出中注册变量,并在build任务状态clone更改时调用任务

例如:

---
# tasks of role: foo

- name: clone repository
  git: repo=git@bitbucket.org:foo/foo.git
       dest={{ foo.dir }}
       accept_hostkey=yes
  register: gitclone

- name: create build dir
  file: state=directory path={{ foo.build_dir }}

- name: build
  command: "{{ item }} chdir={{ foo.build_dir }}"
  with_items:
    - cmake ..
    - make
  when: gitclone.changed
Run Code Online (Sandbox Code Playgroud)

  • 如果有多个步骤并且我想在其中任何一个返回更改时触发处理程序怎么办? (3认同)
  • when:step1.changed或step2.changed或step3.changed (3认同)
  • 不,这是当git将从远程存储库接收更新时收到`notification`.国家无法得救 (2认同)
  • 如果构建失败,后续运行是否会不再尝试构建,因为 gitclone.changed 不再为真?或者 Ansible 是否足够聪明来正确处理这个问题? (2认同)