libcmds: Add support for authentication with gitlab CI
Gitlab CI predefine many variables in its environment, among them the sever hostname and a token that can be used to authenticate with the server. If we find these variables in the environment add the credentials to .netrc which in turn allow git and other tools to access resources found on the CI server. Signed-off-by: Alban Bedel <alban.bedel@aerq.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
@@ -170,7 +170,14 @@ class SetupHome(Command):
|
||||
with open(self.tmpdirname + '/.wgetrc', 'w') as fds:
|
||||
fds.write('\n')
|
||||
with open(self.tmpdirname + '/.netrc', 'w') as fds:
|
||||
fds.write('\n')
|
||||
# Configure the gitlab CI authentification token
|
||||
if os.environ.get('CI_SERVER_HOST', False) \
|
||||
and os.environ.get('CI_JOB_TOKEN', False):
|
||||
fds.write('machine ' + os.environ['CI_SERVER_HOST'] + '\n'
|
||||
'login gitlab-ci-token\n'
|
||||
'password ' + os.environ['CI_JOB_TOKEN'] + '\n')
|
||||
else:
|
||||
fds.write('\n')
|
||||
with open(self.tmpdirname + '/.gitconfig', 'w') as fds:
|
||||
fds.write('[User]\n'
|
||||
'\temail = kas@example.com\n'
|
||||
|
Reference in New Issue
Block a user