import logging
-import os
import click
import jenkins as jenkins_python # Don't confuse this with the function ...
from lftools.cli.jenkins.jobs import jobs
from lftools.cli.jenkins.nodes import nodes
from lftools.cli.jenkins.plugins import plugins_init
+from lftools.jenkins import JJB_INI
log = logging.getLogger(__name__)
@click.pass_context
def jenkins_cli(ctx, server, user, password):
"""Query information about the Jenkins Server."""
- jjb_ini = os.path.join(
- os.path.expanduser('~'),
- '.config',
- 'jenkins_jobs',
- 'jenkins_jobs.ini')
-
if '://' not in server:
- if os.path.isfile(jjb_ini):
+ if JJB_INI:
+ log.debug('Using config from {}'.format(JJB_INI))
config = configparser.ConfigParser()
- config.read(jjb_ini)
+ config.read(JJB_INI)
user = config.get(server, 'user')
password = config.get(server, 'password')
server = config.get(server, 'url')
else:
+ log.debug('jenkins_jobs.ini not found in any of the default paths.')
server = 'https://localhost:8080'
# Initial the Jenkins object and pass it to sub-commands
--- /dev/null
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+"""Jenkins."""
+
+__author__ = 'Thanh Ha'
+
+import logging
+import os
+
+log = logging.getLogger(__name__)
+
+
+def jjb_ini():
+ """Return jenkins_jobs.ini file location if it exists, None otherwise."""
+ global_conf = '/etc/jenkins_jobs/jenkins_jobs.ini'
+ user_conf = os.path.join(
+ os.path.expanduser('~'),
+ '.config',
+ 'jenkins_jobs',
+ 'jenkins_jobs.ini')
+ local_conf = os.path.join(
+ os.getcwd(),
+ 'jenkins_jobs.ini')
+
+ conf = None
+ if os.path.isfile(local_conf):
+ conf = local_conf
+ elif os.path.isfile(user_conf):
+ conf = user_conf
+ elif os.path.isfile(global_conf):
+ conf = global_conf
+
+ return conf
+
+
+JJB_INI = jjb_ini()
--- /dev/null
+---
+features:
+ - |
+ We now support locating the jenkins_jobs.ini in all the same default search
+ paths as JJB supports. Specifically in this order:
+
+ #. $PWD/jenkins_jobs.ini
+ #. ~/.config/jenkins_jobs/jenkins_jobs.ini
+ #. /etc/jenkins_jobs/jenkins_jobs.ini