예제 #1
0
def _update_jenkins_config():
    if not os.path.isdir(JOBS_CONFIG_DIR):
        log(
            'Could not find jobs-config directory at expected location, '
            'skipping jenkins-jobs update (%s)' % JOBS_CONFIG_DIR, ERROR)
        return

    log('Updating jenkins config @ %s' % JENKINS_CONFIG_FILE)
    if not os.path.isfile(JENKINS_SECURITY_FILE):
        log('Could not find jenkins config file @ %s, skipping.' %
            JENKINS_SECURITY_FILE)
        return

    # open existing config.xml and manipulate to enable
    # our security rules, use parser to don't overwrite it
    tree = ET.parse(JENKINS_CONFIG_FILE)
    securityItem = tree.find('useSecurity')
    if securityItem is not None:
        securityItem.text = 'True'
    else:
        # create security item
        root = tree.getroot()
        parent = root.find(".")
        securityItem = ET.SubElement(parent, 'useSecurity')
        securityItem.text = 'True'

    # now replace authorization strategy with our bits
    root = tree.getroot()
    auth = root.find('authorizationStrategy')
    if auth is not None:
        root.remove(auth)

    # create our own tree with security bits
    secElement = ET.parse(JENKINS_SECURITY_FILE)
    root.append(secElement.getroot())

    tree.write(JENKINS_CONFIG_FILE)
    cmd = ['chown', 'jenkins:nogroup', JENKINS_CONFIG_FILE]
    subprocess.check_call(cmd)
    os.chmod(JENKINS_CONFIG_FILE, 0o644)

    # restart only if needed
    restart_on_change({JENKINS_CONFIG_FILE: ['jenkins']})
예제 #2
0
def _update_jenkins_config():
    if not os.path.isdir(JOBS_CONFIG_DIR):
        log('Could not find jobs-config directory at expected location, '
            'skipping jenkins-jobs update (%s)' % JOBS_CONFIG_DIR, ERROR)
        return

    log('Updating jenkins config @ %s' % JENKINS_CONFIG_FILE)
    if not os.path.isfile(JENKINS_SECURITY_FILE):
        log('Could not find jenkins config file @ %s, skipping.' %
            JENKINS_SECURITY_FILE)
        return

    # open existing config.xml and manipulate to enable
    # our security rules, use parser to don't overwrite it
    tree = ET.parse(JENKINS_CONFIG_FILE)
    securityItem = tree.find('useSecurity')
    if securityItem is not None:
        securityItem.text = 'True'
    else:
        # create security item
        root = tree.getroot()
        parent = root.find(".")
        securityItem = ET.SubElement(parent, 'useSecurity')
        securityItem.text = 'True'

    # now replace authorization strategy with our bits
    root = tree.getroot()
    auth = root.find('authorizationStrategy')
    if auth is not None:
        root.remove(auth)

    # create our own tree with security bits
    secElement = ET.parse(JENKINS_SECURITY_FILE)
    root.append(secElement.getroot())

    tree.write(JENKINS_CONFIG_FILE)
    cmd = ['chown', 'jenkins:nogroup', JENKINS_CONFIG_FILE]
    subprocess.check_call(cmd)
    os.chmod(JENKINS_CONFIG_FILE, 0644)

    # restart only if needed
    restart_on_change({JENKINS_CONFIG_FILE: ['jenkins']})
예제 #3
0
 def wrapper(f):
     if is_paused():
         return f
     else:
         return restart_on_change(restart_map)(f)
예제 #4
0
 def wrapper(f):
     if is_paused():
         return f
     else:
         return restart_on_change(restart_map)(f)