#!/usr/bin/env perl # Copyright (C) 2017 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 =head1 NAME qt-jenkins-deploy.pl - deploy Jenkins configuration from templates =head1 SYNOPSIS # jenkins.conf contains template for various Jenkins jobs and nodes... $ ./qt-jenkins-deploy.pl --conf jenkins.conf --user admin Jenkins API token or password for admin: ****** job QtBase_master_Integration: no changes required job QtDeclarative_master_Integration: updated: - this - that + newthis + newthat node ubuntu-builder-01: created node ubuntu-builder-02: created (...) Quickly deploy or update a set of Jenkins jobs and nodes, based on some local configuration files. This script provides a means for maintaining Jenkins configuration as flat files (e.g. under source control with code review), and deploying various Jenkins jobs or nodes from a single template (which is otherwise cumbersome to accomplish). =head2 OPTIONS =over =item --conf Mandatory. Use the specified configuration . See L for details on the configuration format. =item --user Use the specified username for authentication with Jenkins. This may be omitted if the Jenkins instance does not require authentication. =item --password Use the specified API token or password for authentication with Jenkins. If omitted, and --user is specified, the script will prompt. =item --dry-run If set, no Jenkins data will be modified; the script will instead print the changes it would make, then exit. =back =head2 TEMPLATE FILES The Jenkins job and node settings are stored in XML files. This script loads XML templates using the Template Toolkit. Here is a complete example of a templated node XML: [% name %] CI node. Contact: [% contact %] [automatically created] [% root %] 1 EXCLUSIVE When the template is processed, directives within '[% ... %]' blocks are replaced with values calculated from the configuration file. For more details on template syntax, see http://template-toolkit.org/ or `perldoc Template::Manual'). =head2 CONFIGURATION FILE This script uses an INI-style configuration file to declare the jobs and nodes to be managed. Unless otherwise stated, each variable mentioned here may also be used from within a template file. The following sections are handled: =over =item [job.] Manage a job of the given name. Within a job template, this is accessible as the 'name' variable. The following attributes may be configured on a job: =over =item enabled If 0, the Jenkins job is disabled. Defaults to 1. =item pretend If 1, the Jenkins job should operate in pretend mode. The semantics of pretend mode depends on the job content, but generally implies that no destructive/permanent effects result from the job. Defaults to 0. =item gerrit_host Hostname of the Gerrit server. =item gerrit_port Port number of the Gerrit server. Defaults to 29418. =item gerrit_project Project name on the Gerrit server (e.g. "qt/qtbase"). The default is derived from the first portion of the job name; for example, a job name of "QtBase_master_Integration" results in "qt/qtbase". =item custom_repository Custom repository if needed. Defaults to empty. =item testconfig_project Project name used for the qtqa/testconfig repository (e.g. "QtBase master Integration"). Note that underscores and whitespace are treated as equivalent. The default is equal to the job name. =item branch Short name of the branch to test (e.g. "master"). The default is derived from the second portion of the job name; for example, a job name of "QtBase_master_Integration" results in "master". =item poll_cron cron-style line for SCM polling (see SCM poll documentation in Jenkins for syntax details). If omitted, SCM polling is disabled. =item trigger_cron cron-style line for periodic triggering of the job. If omitted, the job is not triggered periodically. =item publish_xunit Parameter to enable xUnit jenkins plugin. Default is not to publish. =item publish_build Parameter to publish build results via another Jenkins dashboar, like https://builds.qt-project.org/. Default is not to publish. =item run_remote_job Parameter to enable additional build step after default job config. Default is not to run =item remote_jenkins Parameter to configure remote Jenkins' URL, where to run the remote job. =item remote_jenkins_job Parameter to configure the remote job to be run. =item log_days_to_keep =item log_num_to_keep Variables to configure how jenkins should store the log items. =item configurations A list of space-separated test/build configurations, e.g. "linux-g++-32_Ubuntu_10.04_x86 win32-msvc2010_Windows_7". It is possible to set a top-level list of configurations, then add or subtract from that list for specific jobs by adding a 'configuration += ...' or 'configuration -= ...' line, as in the following example: # default tests on each major desktop platform... configurations = linux mac win # ...but this job is not supported on windows [job.Some_Unix_Thing] configurations -= win Note that only one 'configurations +=' or 'configurations -=' directive may appear in each block. =item jenkins_url URL of the Jenkins server on which the job should be managed. =item log_upload_url URL to which CI logs should be uploaded (e.g. via ssh). =item log_download_url URL from which CI logs should be downloaded (e.g. via http, to be linked to from gerrit). =item job_template Path to the template XML file to be POSTed to Jenkins. If a relative path, it is interpreted relative to the configuration file. See L