我通过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有何不同?尽管以gcloud
用户身份运行,但/root/.config
想要访问tomcat
会有什么不同?
答案 0 :(得分:1)
在我的系统上,Jenkins以用户tomcat
运行,但环境变量HOME
设置为/root
。
要使Jenkins中的所有内容都更加健全,请将以下行添加到Jenkins脚本的顶部:
export HOME=/home/tomcat
编辑2016/11/21:更好:您可以将该环境变量添加到您的Jenkins全局配置中,在&#34; Manage Jenkins&#34; →&#34;配置系统&#34; →&#34;全球属性&#34;