我使用 Jenkins 运行官方掌舵图,在 GKE 上生成 kubernetes pod,我的 中有以下部分Jenkinsfile
:
...
withCredentials([file(credentialsId: "${project}", variable: 'key')]) {
withEnv(["GOOGLE_APPLICATION_CREDENTIALS=${key}"]) {
sh("gcloud --verbosity=debug auth activate-service-account --key-file ${key} --project=${project_id}")
sh("gcloud --verbosity=debug container clusters get-credentials ${project} --zone europe-west1-b")
...
这是随机失败的,以下是没有什么帮助的输出:
+ gcloud --verbosity=debug container clusters get-credentials tastetastic --zone europe-west1-b
DEBUG: Running gcloud.container.clusters.get-credentials with Namespace(_deepest_parser=ArgumentParser(prog='gcloud.container.clusters.get-credentials', usage=None, description='Updates a kubeconfig file with appropriate credentials to point\nkubectl at a Container Engine Cluster. By default, credentials\nare written to HOME/.kube/config. You can provide an alternate\npath by setting the KUBECONFIG environment variable.\n\nSee [](https://cloud.google.com/container-engine/docs/kubectl) for\nkubectl documentation.', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=False), _specified_args={'verbosity': '--verbosity', 'name': 'NAME', 'zone': '--zone'}, account=None, api_version=None, authority_selector=None, authorization_token_file=None, calliope_command=<googlecloudsdk.calliope.backend.Command object at 0x7f48d48e6e10>, command_path=['gcloud', 'container', 'clusters', 'get-credentials'], configuration=None, credential_file_override=None, document=None, flatten=None, format=None, h=None, help=None, http_timeout=None, log_http=None, name='$project', project=None, quiet=None, trace_email=None, trace_log=None, trace_token=None, user_output_enabled=None, verbosity='debug', version=None, zone='europe-west1-b').
Fetching cluster endpoint and auth data.
DEBUG: unable to load default kubeconfig: [Errno 2] No such file or directory: '/home/jenkins/.kube/config'; recreating /home/jenkins/.kube/config
DEBUG: Saved kubeconfig to /home/jenkins/.kube/config
kubeconfig entry generated for $project.
INFO: Display format "default".
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code -1
Finished: FAILURE
你知道这是从何而来的吗?
如何进一步调试此随机故障?
最后,循环 5 次,是否可以确保避免任何网络故障?
看起来我做的很好: https://github.com/NYTimes/drone-gke/blob/f23a63fd8269182c4ce1d86302e1affc505b6441/main.go#L145