简体   繁体   English

如何使用 Jenkins 管道在 GCP 上创建 VM

[英]How to Create a VM on GCP using Jenkins Pipeline

I tried to create a VM using gcloud directly in pipeline with this command,我尝试使用此命令直接在管道中使用 gcloud 创建一个 VM,

pipeline {管道{

      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

                        }
               } 
  }

I tried passing auth-key but not finding the correct syntax to do it, can anyone help?我尝试传递 auth-key 但没有找到正确的语法来做到这一点,有人可以帮忙吗?

The syntax is a next, even though there are a bunch of other steps to follow to achieve the connection and be able to create the machine, please follow this guide Using Jenkins for distributed builds on Compute Engine , which among such mentioned step we will show you a code example:语法是下一个,即使有很多其他步骤可以实现连接并能够创建机器,请按照本指南使用 Jenkins 在 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在管道中启动 GCP VM? - How to start a GCP VM in a pipeline? 如何使用 Terraform 在 GCP 中创建具有最新快照的 VM 实例 - How to create an VM instance in GCP with latest snapshot using Terraform 如何在 GCP 中创建 Windows VM,以便我们可以在 Jenkins 中使用它进行自动化测试 - How to create a Windows VM in GCP such that we can use it in Jenkins for automated tests 如何在GCP VM实例上创建ansible主服务器? - How to create ansible master on GCP VM instance? 如何使用 terraform 停止 GCP vm 实例 - How to stop GCP vm instances using terraform 如何使用nodejs google-cloud / compute工具从快照在GCP上创建VM实例 - How to create a VM instance on GCP from a snapshot using the nodejs google-cloud/compute tool Terraform 在使用 GCP 提供程序创建 VM 时应用抛出错误 - Terraform apply throwing an Error while create a VM using GCP provider 通过 shell 脚本在 GCP VM 上部署 Jenkins - Jenkins deployment on GCP VM via shell script 如何禁用 GCP 服务帐户来创建 VM 实例? - How can I disable a GCP Service Account to create VM instances? 如何在 gcp 中的 rhel7 linux vm 上创建 postgresql 服务器 - how to create postgresql server on rhel7 linux vm in gcp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM