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