Use a jarargs variable in config.py instead of placing it everywhere.
This commit is contained in:
parent
93f61e5523
commit
d9d1ff8dfe
|
@ -18,8 +18,7 @@ important credentials which allow the backend to work with Jenkins' API.
|
|||
The `jenkins_creds.py` file should look like the following:
|
||||
```
|
||||
jenkins_host = 'https://sdk.dyne.org:4443'
|
||||
jenkins_user = 'toaster'
|
||||
jenkins_pass = 'thetoasterpassword'
|
||||
jenkins_cred = 'toaster:thetoasterpassword'
|
||||
```
|
||||
|
||||
These files will be read and imported by `sync_jobs.py` when ran.
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from jenkins_creds import (jenkins_host, jenkins_cred)
|
||||
|
||||
# Path to jenkins-cli.jar
|
||||
jarpath = '/var/cache/jenkins/war/WEB-INF/jenkins-cli.jar'
|
||||
|
||||
# jar parameters
|
||||
jarargs = ['java', '-jar', jarpath, '-s', jenkins_host, '-auth', jenkins_cred]
|
||||
|
||||
# Physical path to where jobs are held
|
||||
jobpath = '/srv/toaster'
|
||||
|
|
|
@ -6,8 +6,7 @@ Module for backend talk with Jenkins executed by the web/CGI
|
|||
from argparse import ArgumentParser
|
||||
from subprocess import run
|
||||
|
||||
from config import jarpath, jobpath
|
||||
from jenkins_creds import (jenkins_host, jenkins_user, jenkins_pass)
|
||||
from config import (jarargs, jobpath)
|
||||
|
||||
|
||||
def html_escape(string):
|
||||
|
@ -53,23 +52,20 @@ def add_job(jobname):
|
|||
for i in replacements:
|
||||
sdk_job = sdk_job.replace('{{{%s}}}' % i[0], i[1])
|
||||
|
||||
creds = '%s:%s' % (jenkins_user, jenkins_pass)
|
||||
clijob = run(['java', '-jar', jarpath, '-s', jenkins_host, '-auth', creds,
|
||||
'create-job', jobname.replace('@', 'AT')],
|
||||
input=sdk_job.encode())
|
||||
jarargs.append('create-job')
|
||||
jarargs.append(jobname.replace('@', 'AT'))
|
||||
|
||||
return clijob
|
||||
return run(jarargs, input=sdk_job.encode())
|
||||
|
||||
|
||||
def del_job(jobname):
|
||||
"""
|
||||
Function for deleting a Jenkins job.
|
||||
"""
|
||||
creds = '%s:%s' % (jenkins_user, jenkins_pass)
|
||||
clijob = run(['java', '-jar', jarpath, '-s', jenkins_host, '-auth', creds,
|
||||
'delete-job', jobname.replace('@', 'AT')])
|
||||
jarargs.append('delete-job')
|
||||
jarargs.append(jobname.replace('@', 'AT'))
|
||||
|
||||
return clijob
|
||||
return run(jarargs)
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -88,7 +84,6 @@ def main():
|
|||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
if args.add:
|
||||
if args.dryrun:
|
||||
print('Would add:', args.jobname)
|
||||
|
|
Loading…
Reference in New Issue