我的项目使用 Terraform 来设置 CI/CD 的基础设施和 Github Actions。运行后,terraform apply我想将 Terraform 输出变量的值保存为 Github Action 环境变量,以供工作流程稍后使用。
根据 Github Action 的文档,这是使用工作流命令创建或更新环境变量的方法。
这是我简化的 Github Action 工作流程:
name: Setup infrastructure
jobs:
run-terraform:
name: Apply infrastructure changes
runs-on: ubuntu-latest
steps:
...
- run: terraform output vm_ip
- run: echo TEST=$(terraform output vm_ip) >> $GITHUB_ENV
- run: echo ${{ env.TEST }}
Run Code Online (Sandbox Code Playgroud)
当本地运行时,命令echo TEST_VAR=$(terraform output vm_ip)输出准确TEST="192.168.23.23",但从 Github Action CLI 输出中我得到一些非常奇怪的东西:
我尝试过使用单引号、双引号。在某些时候我改变了策略并尝试使用jq. 因此,我添加了以下步骤,以便将所有 Terraform 输出导出到 json 文件并使用以下命令解析它jq:
- …Run Code Online (Sandbox Code Playgroud) continuous-integration json environment-variables terraform github-actions
目前,我正在尝试使用 GitHub Actions 将应用程序的凹凸版本自动化,作为 PR 合并的一部分。有一个自定义脚本可以识别应用程序的当前版本和 PR 附带的标签,并在存储版本号的文件上相应地更改主要|次要|补丁版本。重要的是,版本碰撞仅在合并 PR 时发生,并且作为 GitHub Actions 的一部分,因为它有助于避免版本文件中的合并冲突,并消除了手动碰撞版本的方式。
下面给出了 GitHub Actions 代码片段。
jobs:
release:
# Skip on Pull Request Close event.
if: "!(github.event_name == 'pull_request' && !github.event.pull_request.merged)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- id: bumpversion
if: github.event.pull_request.merged
env:
PR_LABELS: ${{ toJson(github.event.pull_request.labels) }}
run: bash .github/scripts/bump_version.sh -l "${PR_LABELS}"
Run Code Online (Sandbox Code Playgroud)
该bump_version.sh脚本具有下面给出的函数,该函数可以进行版本更改,然后将其推送到分支main。
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
echo "commiting the version bump changes..."
git add .
git commit -m "Bump …Run Code Online (Sandbox Code Playgroud) versioning github pull-request semantic-versioning github-actions
我正在将 EC2 作为自托管运行器运行。我已将 AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY 导出到 EC2,我可以看到它们是用printenv命令设置的。
这样做的原因是我不想将 AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY 保存在 github 秘密中。
有什么方法可以在我的 github 操作工作流程中访问和使用环境变量(AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY)?
continuous-integration amazon-ec2 devops github-actions cicd
下面显示了典型构建的 Github Actions 选项卡显示的内容:
构建步骤实际上有许多子步骤,但我不想使用 Github Actions 作为脚本语言,只是为了能够谨慎地显示每个子步骤。Github Actions 是否提供了某种魔力来表明您希望构建的可视化显示离散步骤(即“动态步骤”)?
我希望出现类似以下内容的内容,这会导致在 Github Actions 构建可视化的输出中创建离散结果节点:
- name: Dynamic Steps
run |
echo "###github-action-step: Step 1"
echo "###github-action-step: Step 2"
echo "###github-action-step: Step 3"
Run Code Online (Sandbox Code Playgroud) 我正在使用 GitHub actions 来管理我的 CI,以下事件会触发我的工作流程:
on:
pull_request:
branches: main
push:
branches: main
Run Code Online (Sandbox Code Playgroud)
我观察到以下“问题”:当我创建 PR 时,CI 就会运行。如果测试通过并且我将其合并到 main 中,则会再次运行测试(在特定情况下我不希望这样做)。如何设置我的工作流程,以便在合并 PR(CI 已通过 PR)时不会触发 CI?
提前致谢!
我在 github 操作中创建了秘密,并尝试在可重用的工作流程中使用它们,但我无法使其工作,但是,如果我传递从调用者文件中硬编码的秘密,它就可以正常工作
## set_env.yml
name: Sent Env Creds and Vars
on:
push:
branches:
- main
- dev
pull_request:
branches: [ main ]
jobs:
deploy-dev:
uses: ./.github/workflows/main.yml
with:
AWS_REGION: "us-east-2"
PREFIX: "dev"
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
Run Code Online (Sandbox Code Playgroud)
可重用的工作流程 = main.yml
## main.yml
name: Deploy to AWS
# Controls when the workflow will run
on:
workflow_call:
inputs:
AWS_REGION:
required: true
type: string
PREFIX:
required: true
type: string
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
# A workflow …Run Code Online (Sandbox Code Playgroud) 我正在使用 Github Actions 构建一些要推送到 Azure 容器注册表的 Docker 映像。我正在尝试基于此 GH Action使用 OIDC 作为身份验证机制。我知道该操作支持其他身份验证策略,出于某种原因,我已在我的用例中放弃了这些策略。
根据GH 文档,需要根据 GH 帐户、存储库名称和分支名称填充“主题”字段。然而,想要为多个分支构建 Docker 镜像,这似乎需要每个分支一个联合配置 - 在我看来,这不切实际。
所以我的问题是:有谁知道是否可以(以及如何)设置一个带有“主题”值的联合配置,该值可以作为某种通配符,涵盖给定存储库中的所有分支?
谢谢!
我有一个工作流程步骤,循环运行 shell 命令的最后阶段:
|| echo "::error Filename $filename doesn't match possible files" && exit 1 ; done
退出被适当触发,但我看到的唯一注释是:
错误:进程已完成,退出代码为 1。
日志显示了整个 shell 命令管道以及相同的错误消息,但不是我的回显错误。
如何获取我的输出,包括 $filename 变量?
如何在 Github Actions 中指定架构(类似x86或arm64)?
我正在遵循 HashiCorp 的学习指南,了解如何设置 GitHub Actions 和 terraform。除了使用 Terraform 计划更新 PR 的步骤之外,一切都运行良好。
\n我遇到以下错误:
\n\nAn error occurred trying to start process \'/home/runner/runners/2.287.1/externals/node12/bin/node\' with working directory \'/home/runner/work/ccoe-aws-ou-scp-manage/ccoe-aws-ou-scp-manage\'. Argument list too long\n\nRun Code Online (Sandbox Code Playgroud)\n我正在使用的代码是:
\n - uses: actions/github-script@0.9.0\n if: github.event_name == \'pull_request\'\n env:\n PLAN: "terraform\\n${{ steps.plan.outputs.stdout }}"\n with:\n github-token: ${{ secrets.GITHUB_TOKEN }}\n script: |\n const output = `#### Terraform Format and Style \\`${{ steps.fmt.outcome }}\\`\n #### Terraform Initialization \xe2\x9a\x99\xef\xb8\x8f\\`${{ steps.init.outcome }}\\`\n #### Terraform Plan \\`${{ steps.plan.outcome }}\\`\n <details><summary>Show Plan</summary>\n \\`\\`\\`${process.env.PLAN}\\`\\`\\`\n </details>\n *Pusher: …Run Code Online (Sandbox Code Playgroud) github-actions ×10
github ×5
terraform ×3
cicd ×2
amazon-ec2 ×1
azure ×1
devops ×1
json ×1
pull-request ×1
versioning ×1