google-cloud-platform - 如何在 Cloud Build 中运行 beta gcloud 组件,例如“gcloud beta artifacts docker images scan”?
问题描述
我正在尝试在 Cloud Build 管道中包含 Container Analyis API链接。这是一个 beta 组件,我需要先使用命令行安装它:
gcloud components install beta local-extract
然后我可以运行按需容器分析(如果容器在本地存在):
gcloud beta artifacts docker images scan ubuntu:latest
我的问题是如何在 Cloud Build中使用beta local-extract之类的组件?
我试图迈出第一步并安装缺少的组件L
## Update components
- name: 'gcr.io/cloud-builders/gcloud'
args: ['components', 'install', 'beta', 'local-extract', '-q']
id: Update component
但是一旦我进入下一步,更新就消失了(因为它不在容器中)
我还尝试安装该组件,然后使用 (& 或 ;) 运行扫描,但它失败了:
## Run vulnerability scan
- name: 'gcr.io/cloud-builders/gcloud'
args: ['components', 'install', 'beta', 'local-extract', '-q', ';', 'gcloud', 'beta', 'artifacts', 'docker', 'images', 'scan', 'ubuntu:latest', '--location=europe']
id: Run vulnaribility scan
我得到:
Already have image (with digest): gcr.io/cloud-builders/gcloud
ERROR: (gcloud.components.install) unrecognized arguments:
;
gcloud
beta
artifacts
docker
images
scan
ubuntu:latest
--location=europe (did you mean '--project'?)
To search the help text of gcloud commands, run:
gcloud help -- SEARCH_TERMS
所以我的问题是:
- 如何在 Cloud Build 中运行“gcloud beta artifacts docker images scan ubuntu:latest”?
- 奖励:从上一个命令中,我如何获得需要作为参数传递给下一步的“扫描”输出值?(我想应该是--format)
解决方案
您应该尝试使用cloud-sdk
docker 映像:
https://github.com/GoogleCloudPlatform/cloud-sdk-docker
Cloud Build 团队(隐含地?)推荐它:
https://github.com/GoogleCloudPlatform/cloud-builders/tree/master/gcloud
使用cloud-sdk-docker
容器,您可以将入口点更改为一起bash
管道gcloud
命令。这是一个(丑陋的)示例:
至于你的奖金问题。是的,--format=value(the.name.of.the.field)
可能就是你想要的。诀窍是知道该字段的名称。我通常从--format=json
我的开发工作站开始找出名称。
推荐阅读
- azure - 如何使用 Powershell 在 Azure 中托管的服务上调用方法?
- html - CakePHP 3.7.1 向表单选择控件选项添加类
- orm - Coldfusion EntityLoad 读取计算字段
- sql - 如何选择总和但包含其他列?
- android-studio - 错误:“选择树中的配置元素以编辑其设置”
- php - 如何以模态形式提醒成功消息?
- angular - 拖放 Angular 7
- excel - 数组公式查找一年内具有指定服务类型的客户
- linux - 试图获得确切的 grep 属性以给出包含整个句子的结果
- azure - 无法使用我的 hotmail 帐户创建新的 Azure Devops MSA 帐户。我有一个链接到我的组织的 AD Devops 帐户,该帐户运行良好