Allows params to be specified via environment variables

Adds ability to load common params from environment variables:
JJB_CONF
JJB_LOG_LEVEL
JJB_SECTION
JJB_USER
JJB_PASSWORD

Change-Id: Ida786f2e60e4b3e54d739436d0970917a5f93518
This commit is contained in:
Sorin Sbarnea 2018-03-27 11:28:56 +01:00
parent a67c4cab87
commit d47634fc3f
1 changed files with 13 additions and 7 deletions

View File

@ -14,6 +14,7 @@
# under the License.
import argparse
import os
import jenkins_jobs.version
@ -32,13 +33,14 @@ def create_parser():
parser.add_argument(
'--conf',
dest='conf',
help="configuration file")
default=os.environ.get('JJB_CONF', None),
help="configuration file [JJB_CONF]")
parser.add_argument(
'-l',
'--log_level',
dest='log_level',
default='info',
help="log level (default: %(default)s)")
default=os.environ.get('JJB_LOG_LEVEL', 'info'),
help="log level (default: %(default)s) [JJB_LOG_LEVEL]")
parser.add_argument(
'--ignore-cache',
action='store_true',
@ -68,16 +70,20 @@ def create_parser():
parser.add_argument(
'--server', '-s',
dest='section',
default='jenkins',
help="The Jenkins server ini section to use. Defaults to 'jenkins'")
default=os.environ.get('JJB_SECTION', 'jenkins'),
help="The Jenkins server ini section to use. Defaults to 'jenkins' "
"[JJB_SECTION]")
parser.add_argument(
'--user', '-u',
default=os.environ.get('JJB_USER', None),
help="The Jenkins user to use for authentication. This overrides "
"the user specified in the configuration file.")
"the user specified in the configuration file. [JJB_USER]")
parser.add_argument(
'--password', '-p',
default=os.environ.get('JJB_PASSWORD', None),
help="Password or API token to use for authenticating towards Jenkins."
" This overrides the password specified in the configuration file.")
" This overrides the password specified in the configuration file."
" [JJB_PASSWORD]")
subparser = parser.add_subparsers(
dest='command',