使用gh创建仓库环境

5
2个回答

8

从我所看到这里在 gh cli 仓库中,现在可能还无法实现。此问题[已链接]是一个专门针对增强请求的问题。

我也想知道是否可以实现,因为将环境秘密信息注入工作流程是我的一部分。

但您仍然可以使用 API 创建它。

curl -X PUT \
-H 'Authorization: Bearer ghp_...' \
-H 'Accept: application/vnd.github.v3+json' \
https://api.github.com/repos/<org>/<repo>/environments/<env>

或者,也可以使用gh完成相同的操作:

gh api --method PUT -H "Accept: application/vnd.github+json" \
repos/<org>/<repo>/environments/<env>

谢谢,有没有办法指定deployment_branches?我尝试了-d '{"deployment_branches":["branch1", "branch2"]}' https://docs.github.com/en/rest/reference/deployments#create-or-update-an-environment - gary69

3

基本上,您需要先创建环境,然后才能设置分支策略:

jq -n '{"deployment_branch_policy": {"protected_branches": false, "custom_branch_policies": true}}'|gh api -H "Accept: application/vnd.github+json" -X PUT /repos/:owner/:repo/environments/dev --input -

gh api --method POST -H "Accept: application/vnd.github+json" "/repos/Oceaneering/it_infra_base_application_bootstrapper/environments/dev/deployment-branch-policies" -f name=dev

我为我的用例编写了一个Python脚本,它使用gh cli创建环境并可以包含分支模式。

https://gist.github.com/walkerk1980/8a6f6879b32260360854a89bb880a48d


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接