在Jenkins管道中执行gcloud命令

在Jenkins管道中执行gcloud命令

本文介绍了在Jenkins管道中执行gcloud命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在Jenkins声明性管道中运行gcloud命令,如以下示例所示:

I'm trying to run the gcloud command in a Jenkins declarative pipeline just like in the following example:

pipeline {
    agent any

   stages {
      stage('Run gcloud version') {

         steps {
            sh 'gcloud --version'
         }
      }
   }
}

我下载了"GCloud SDK插件"并进行了如下配置(在Jenkins的全局工具配置"中):

I downloaded the "GCloud SDK Plugin" and configured it like this (in "Global Tool Configuration" for Jenkins):

但是当我尝试使用上述Jenkinsfile构建管道时,管道中出现"gcloud:not found"错误.

but when I try to build the pipeline using the above Jenkinsfile, I'm getting a 'gcloud: not found' error in the pipeline.

推荐答案

我能够使用以下Jenkinsfile运行命令:

I was able to run the command using the following Jenkinsfile:

pipeline {
   agent any

stages {
    stage('Run gcloud') {

        steps {
            withEnv(['GCLOUD_PATH=/var/jenkins_home/google-cloud-sdk/bin']) {
                sh '$GCLOUD_PATH/gcloud --version'
            }


         }
      }
   }
}

注意:我正在kubernetes中运行Jenkins,所以首先我必须在Jenkins pod中安装gcloud sdk

Note: I'm running Jenkins in kubernetes, so first I had to install the gcloud sdk in the Jenkins pod

这篇关于在Jenkins管道中执行gcloud命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:00