Ошибка запуска скриптов gcloud в конвейере в jenkins - PullRequest
0 голосов
/ 10 апреля 2019

Я создаю приложение Jenkins в Kubernetes, используя рыночную установку по клику для развертывания с облачной платформы Google, когда я хочу использовать команду GCloud, после установки плагина Gcloud появляется сообщение Log:

Это конвейер .

def project = 'my-project'
def appName = 'my_app-name'
def zone = 'us-east1-d'
def feSvcName = "${appName}"
def imageTag = "gcr.io/${project}/${appName}:${env.BRANCH_NAME}.${env.BUILD_NUMBER}"

pipeline {
  agent  any
    stages {
      stage('Test') {
        steps {  
          sh " echo Test is not avalaible"
        }
      }
    stage('Build and push image with Container Builder') {
      steps {
        container('gcloud') {
          sh "cd .."
          sh "PYTHONUNBUFFERED=1 gcloud builds submit -t ${imageTag} ."
        }
      }
    }
    stage('Deploy Development') {
      // Canary branch
      when { branch 'develop' }
      steps {
        container('kubectl') {
          sh ("echo BRANCH develop is not avalaible")

        }
      }
    }
    stage('Deploy Test') {
      // Canary branch
      when { branch 'develop' }
      steps {
        container('kubectl') {
          sh ("echo BRANCH develop is not avalaible")

        }
      }
    }
    stage('Deploy Production') {
      // Production branchh
      when { branch 'master' }
      steps {
        container('kubectl') {
          sh ("echo BRANCH Master is not avalaible")

        }
      }
    }

  }
}

LOG

 > git rev-parse --is-inside-work-tree # timeout=10
Setting origin to https://source.developers.google.com/p/test-jalfonso/r/hello-app
 > git config remote.origin.url https://source.developers.google.com/p/test-jalfonso/r/hello-app # timeout=10
Fetching origin...
Fetching upstream changes from origin
 > git --version # timeout=10
 > git config --get remote.origin.url # timeout=10
using GIT_ASKPASS to set credentials test-jalfonso
 > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/master
Seen branch in repository origin/test
Seen 2 remote branches
Obtained Jenkinsfile from 3e1b0fd042813f25f4761bec13a50646d7a3fccf
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/test-jalfonso_test@2
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential source:test-jalfonso
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository https://source.developers.google.com/p/test-jalfonso/r/hello-app
 > git init /var/jenkins_home/workspace/test-jalfonso_test@2 # timeout=10
Fetching upstream changes from https://source.developers.google.com/p/test-jalfonso/r/hello-app
 > git --version # timeout=10
using GIT_ASKPASS to set credentials test-jalfonso
 > git fetch --no-tags --progress https://source.developers.google.com/p/test-jalfonso/r/hello-app +refs/heads/*:refs/remotes/origin/*
 > git config remote.origin.url https://source.developers.google.com/p/test-jalfonso/r/hello-app # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url https://source.developers.google.com/p/test-jalfonso/r/hello-app # timeout=10
Fetching without tags
Fetching upstream changes from https://source.developers.google.com/p/test-jalfonso/r/hello-app
using GIT_ASKPASS to set credentials test-jalfonso
 > git fetch --no-tags --progress https://source.developers.google.com/p/test-jalfonso/r/hello-app +refs/heads/*:refs/remotes/origin/*
Checking out Revision 3e1b0fd042813f25f4761bec13a50646d7a3fccf (test)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 3e1b0fd042813f25f4761bec13a50646d7a3fccf
Commit message: "test"
> git rev-list --no-walk f0d84e4bb46eff9acd4a79f93013f8eca20370c9 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] sh
+ echo Test is not avalaible
Test is not avalaible
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build and push image with Container Builder)
[Pipeline] sh
+ echo Not available
Not available
[Pipeline] sh
+ gcloud builds submit -t gcr.io/my-project/my-app-name:master.23 .
/var/jenkins_home/workspace/test_master@tmp/durable-1d490c65/script.sh: 1: /var/jenkins_home/workspace/test_master@tmp/durable-1d490c65/script.sh: gcloud: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy Development)
Stage "Deploy Development" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy Test)
Stage "Deploy Test" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy Production)
Stage "Deploy Production" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE

Я попытался найти папку установки SDK Google, но не могу 'Я не знаю, является ли это проблемой развертывания.Я ожидал просто загрузить свой Dockerfile в исходный репозиторий, но если я использую скрипт с Gcloud, появится этот журнал, я установил все плагины для Google auth, SDK, Kubernetes и настроил Kubernetes в Jenkins Config, я экспортирую ключи из GoogleОблако.

1 Ответ

0 голосов
/ 15 апреля 2019

Из вашего конвейерного вывода я вижу, что все ваши этапы выполняются на главном узле Jenkins (где gcloud по умолчанию недоступен), что не так, как вы ожидаете на динамически создаваемом модуле jenkins-slave Pod в кластере Kubernetes.

Чтобы быстро решить проблему, просто явно настройте шаблон Pod в коде конвейера Jenkins. Вот пример шаблона Pod, включающего контейнер 'gcloud':

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, особенно часть конфигурации, относящейся к шаблону Pod Kubernetes, как описано здесь .

...