gpt4 book ai didi

git - 如何使用 Ansible 查看最近的 git 标签?

转载 作者:太空狗 更新时间:2023-10-29 13:33:39 24 4
gpt4 key购买 nike

有没有一种简单的方法可以让 Ansible 检查特定 git 分支上的最新标签,而无需指定或传入标签?也就是说,Ansible 能否检测或导出分支上的最新标记,或者是否需要使用 shell 模块或其他东西单独完成?

最佳答案

Ansible 没有将 checkout 最新标签作为内置功能。它的 git 模块确实有 update 参数,这将确保特定的 repo 与其远程 HEAD 完全同步。

---
- git:
repo=git@github.com:username/reponame.git
dest={{ path }}
update=yes
force=no

如果设置为 false 并且存在未提交的更改,强制将 check out 最新版本的存储库,覆盖未提交的更改或失败。

参见 http://docs.ansible.com/git_module.html有关此模块的更多选项。

此时你可以做两件事:

1) 有一个单独的分支,上面有你的标签,并使用 update 参数保持不变。

2) 您还可以使用 shell 模块并实现类似的东西:Git Checkout Latest Tag

---
- name: get new tags from remote
shell: "git fetch --tags"
args:
chdir: "{{ path }}"

- name: get latest tag name
shell: "git describe --tags `git rev-list --tags --max-count=1`"
args:
chdir: "{{ path }}"
register: latest_tag

然后将该结果用作 git 模块的 refspec

- git:
repo=git@github.com:username/reponame.git
dest={{ path }}
version: latest_tag.stdout

关于git - 如何使用 Ansible 查看最近的 git 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29153650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com