Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jenkins中的管道中运行gcloud脚本时出错_Jenkins_Kubernetes_Jenkins Plugins_Google Kubernetes Engine - Fatal编程技术网

在jenkins中的管道中运行gcloud脚本时出错

在jenkins中的管道中运行gcloud脚本时出错,jenkins,kubernetes,jenkins-plugins,google-kubernetes-engine,Jenkins,Kubernetes,Jenkins Plugins,Google Kubernetes Engine,安装GCloud插件后,如果我想使用GCloud命令,我会在Kubernetes使用marketplace click to deploy从Google云平台创建Jenkins的应用程序,并显示日志消息: 这是管道 日志 我试图搜索谷歌SDK的文件夹安装,但我找不到任何,我不知道是否是部署问题。 我希望只将Dockerfile上传到源代码库,但如果我使用Gcloud脚本显示此日志,我安装了Google auth、SDK、Kubernetes的所有插件,我在Jenkins配置中配置Kubernet

安装GCloud插件后,如果我想使用GCloud命令,我会在Kubernetes使用marketplace click to deploy从Google云平台创建Jenkins的应用程序,并显示日志消息:

这是管道

日志

我试图搜索谷歌SDK的文件夹安装,但我找不到任何,我不知道是否是部署问题。
我希望只将Dockerfile上传到源代码库,但如果我使用Gcloud脚本显示此日志,我安装了Google auth、SDK、Kubernetes的所有插件,我在Jenkins配置中配置Kubernetes,我从Google Cloud导出密钥。

从管道输出中我可以看到,所有阶段都在Jenkins主节点上运行,默认情况下“gcloud”不可用,这与Kubernetes集群上动态创建的Jenkins从站上的预期不同

要快速解决此问题,只需在Jenkins管道代码中显式配置Pod模板,以下是包含“gcloud”容器的Pod模板示例:

def label = "gcloud-command-${UUID.randomUUID().toString()}"

podTemplate(label: label, yaml: """
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: gcloud
    image: gcr.io/cloud-builders/gcloud
    command:
    - cat
    tty: true
"""
  ) {

  node(label) {
    stage('Test -  Execution of gcloud command') {
      container('gcloud') {
        sh "gcloud compute zones --help"
      }
    }

  }
}
作业输出:

Running on jenkins-slave-33v1t-04zwp in /home/jenkins/workspace/run-jenkins-slave-on-k8s
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test -  Execution of gcloud command) (Test -  Execution of gcloud command)
[Pipeline] container
[Pipeline] {
[Pipeline] sh
+ gcloud compute zones --help
NAME
    gcloud compute zones - list Google Compute Engine zones

SYNOPSIS
    gcloud compute zones COMMAND [GCLOUD_WIDE_FLAG ...]

DESCRIPTION
    List Google Compute Engine zones.

GCLOUD WIDE FLAGS
    These flags are available to all commands: --account, --configuration,
    --flags-file, --flatten, --format, --help, --impersonate-service-account,
    --log-http, --project, --quiet, --trace-token, --user-output-enabled,
    --verbosity. Run $ gcloud help for details.

COMMANDS
    COMMAND is one of the following:

     describe
        Describe a Google Compute Engine zone.

     list
        List Google Compute Engine zones.

NOTES
    These variants are also available:

        $ gcloud alpha compute zones
        $ gcloud beta compute zones

[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
Finished: SUCCESS

请验证您是否正确配置了Jenkins Kubernetes插件,尤其是与Kubernetes Pod模板相关的部分配置,如前所述

这很有帮助,谢谢,我在GitHub存储库中看到了插件的配置,并对其进行了配置。
def label = "gcloud-command-${UUID.randomUUID().toString()}"

podTemplate(label: label, yaml: """
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: gcloud
    image: gcr.io/cloud-builders/gcloud
    command:
    - cat
    tty: true
"""
  ) {

  node(label) {
    stage('Test -  Execution of gcloud command') {
      container('gcloud') {
        sh "gcloud compute zones --help"
      }
    }

  }
}
Running on jenkins-slave-33v1t-04zwp in /home/jenkins/workspace/run-jenkins-slave-on-k8s
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test -  Execution of gcloud command) (Test -  Execution of gcloud command)
[Pipeline] container
[Pipeline] {
[Pipeline] sh
+ gcloud compute zones --help
NAME
    gcloud compute zones - list Google Compute Engine zones

SYNOPSIS
    gcloud compute zones COMMAND [GCLOUD_WIDE_FLAG ...]

DESCRIPTION
    List Google Compute Engine zones.

GCLOUD WIDE FLAGS
    These flags are available to all commands: --account, --configuration,
    --flags-file, --flatten, --format, --help, --impersonate-service-account,
    --log-http, --project, --quiet, --trace-token, --user-output-enabled,
    --verbosity. Run $ gcloud help for details.

COMMANDS
    COMMAND is one of the following:

     describe
        Describe a Google Compute Engine zone.

     list
        List Google Compute Engine zones.

NOTES
    These variants are also available:

        $ gcloud alpha compute zones
        $ gcloud beta compute zones

[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
Finished: SUCCESS