Jenkins 命中 shell 中未遇到的权限错误
Jenkins hits permissions error not encountered in shell
我通过 SSH 连接到我的 Jenkins 机器并成功执行命令:
bistenes@jenkins:~$ sudo su tomcat
$ gsutil ls gs://qs-build
gs://qs-build/jenkins-run_cfa_pipeline-47/
$
一切都很好。我尝试 运行 来自 Jenkins 项目的完全相同的命令:
+ whoami
tomcat
+ gsutil ls gs://qs-build
Traceback (most recent call last):
File "/usr/local/bin/../share/google/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 72, in <module>
main()
File "/usr/local/bin/../share/google/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 20, in main
project, account = bootstrapping.GetActiveProjectAndAccount()
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 217, in GetActiveProjectAndAccount
project_name = properties.VALUES.core.project.Get(validate=False)
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/properties.py", line 501, in Get
value = _GetProperty(self, _PropertiesFile.Load(), required)
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/properties.py", line 755, in _GetProperty
value = callback()
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/properties.py", line 370, in <lambda>
lambda: c_gce.Metadata().Project()])
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/credentials/gce.py", line 182, in Metadata
_metadata_lock.lock(function=_CreateMetadata, argument=None)
File "/usr/lib/python2.7/mutex.py", line 44, in lock
function(argument)
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/credentials/gce.py", line 181, in _CreateMetadata
_metadata = _GCEMetadata()
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/credentials/gce.py", line 78, in __init__
_CacheIsOnGCE(self.connected)
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/credentials/gce.py", line 189, in _CacheIsOnGCE
config.Paths().GCECachePath()) as gcecache_file:
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/util/files.py", line 511, in OpenForWritingPrivate
MakeDir(full_parent_dir_path, mode=0700)
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/util/files.py", line 44, in MakeDir
os.makedirs(path, mode=mode)
File "/usr/lib/python2.7/os.py", line 150, in makedirs
makedirs(head, mode)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/root/.config'
Build step 'Execute shell' marked build as failure
Jenkins shell 与我通过 SSH 获得的 shell 有何不同?尽管 运行 作为用户 tomcat
,但有什么不同可能导致 gcloud
想要访问 /root/.config
?
在我的系统上,Jenkins 以用户 tomcat
运行,但环境变量 HOME
设置为 /root
。
为了让 Jenkins 中的一切都以更合理的方式运行,请将以下行添加到 Jenkins 脚本的顶部:
export HOME=/home/tomcat
编辑 2016/11/21: 更好:您可以将该环境变量添加到 Jenkins 全局配置中,在 "Manage Jenkins" → "Configure System" → "Global Properties"
我通过 SSH 连接到我的 Jenkins 机器并成功执行命令:
bistenes@jenkins:~$ sudo su tomcat
$ gsutil ls gs://qs-build
gs://qs-build/jenkins-run_cfa_pipeline-47/
$
一切都很好。我尝试 运行 来自 Jenkins 项目的完全相同的命令:
+ whoami
tomcat
+ gsutil ls gs://qs-build
Traceback (most recent call last):
File "/usr/local/bin/../share/google/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 72, in <module>
main()
File "/usr/local/bin/../share/google/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 20, in main
project, account = bootstrapping.GetActiveProjectAndAccount()
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 217, in GetActiveProjectAndAccount
project_name = properties.VALUES.core.project.Get(validate=False)
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/properties.py", line 501, in Get
value = _GetProperty(self, _PropertiesFile.Load(), required)
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/properties.py", line 755, in _GetProperty
value = callback()
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/properties.py", line 370, in <lambda>
lambda: c_gce.Metadata().Project()])
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/credentials/gce.py", line 182, in Metadata
_metadata_lock.lock(function=_CreateMetadata, argument=None)
File "/usr/lib/python2.7/mutex.py", line 44, in lock
function(argument)
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/credentials/gce.py", line 181, in _CreateMetadata
_metadata = _GCEMetadata()
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/credentials/gce.py", line 78, in __init__
_CacheIsOnGCE(self.connected)
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/credentials/gce.py", line 189, in _CacheIsOnGCE
config.Paths().GCECachePath()) as gcecache_file:
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/util/files.py", line 511, in OpenForWritingPrivate
MakeDir(full_parent_dir_path, mode=0700)
File "/usr/local/share/google/google-cloud-sdk/bin/bootstrapping/../../lib/googlecloudsdk/core/util/files.py", line 44, in MakeDir
os.makedirs(path, mode=mode)
File "/usr/lib/python2.7/os.py", line 150, in makedirs
makedirs(head, mode)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/root/.config'
Build step 'Execute shell' marked build as failure
Jenkins shell 与我通过 SSH 获得的 shell 有何不同?尽管 运行 作为用户 tomcat
,但有什么不同可能导致 gcloud
想要访问 /root/.config
?
在我的系统上,Jenkins 以用户 tomcat
运行,但环境变量 HOME
设置为 /root
。
为了让 Jenkins 中的一切都以更合理的方式运行,请将以下行添加到 Jenkins 脚本的顶部:
export HOME=/home/tomcat
编辑 2016/11/21: 更好:您可以将该环境变量添加到 Jenkins 全局配置中,在 "Manage Jenkins" → "Configure System" → "Global Properties"