google-cloud-platform - 如何使用 Jenkins Pipeline 在 GCP 上创建 VM
问题描述
我尝试使用此命令直接在管道中使用 gcloud 创建一个 VM,
管道{
agent any
stages{
stage('Create a VM'){
gcloud compute instances create centos-7 --image-family=centos-7 --image-project=centos-cloud --zone=europe-west2-c
}
}
}
我尝试传递 auth-key 但没有找到正确的语法来做到这一点,有人可以帮忙吗?
解决方案
语法是下一个,即使有很多其他步骤要遵循来实现连接并能够创建机器,请遵循本指南Using Jenkins for Distributed builds on Compute Engine,在提到的步骤中,我们将展示你一个代码示例:
export PROJECT=$(gcloud info --format='value(config.project)')
cat > jenkins-agent.json <<EOF
{
"builders": [
{
"type": "googlecompute",
"project_id": "$PROJECT",
"source_image_family": "ubuntu-2004-lts",
"source_image_project_id": "ubuntu-os-cloud",
"zone": "us-central1-a",
"disk_size": "10",
"image_name": "jenkins-agent-{{timestamp}}",
"image_family": "jenkins-agent",
"ssh_username": "ubuntu"
}
],
"provisioners": [
{
"type": "shell",
"inline": ["sudo apt-get update && sudo apt-get install -y default-jdk"]
}
]
}
EOF
推荐阅读
- flask - 如何在 pytest 中发送 http 请求”
- angular - Angular 8 Internationalization 在 --prod 环境中创建了一个巨大的 vendor.js 文件
- spring-boot - 获取将千分尺集成到弹性搜索应用程序的异常
- azure-devops - 一次批准多个部署
- angular - 包含的字符串
不会与 ngFor 换行 - python - 如何将 csv 文件中的数据复制到 Postgres 中名为 user 的表中?
- r - 删除多个特定行的功能?
- python - pip freeze 不显示包
- sql - 如何在SQL中找到指定记录之后的下一条记录
- php - 按产品显示使用此查询类别后,但我的网站设计消失了