All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kuali.maven.plugins.jenkins.BaseMojo Maven / Gradle / Ivy

Go to download

Automated management of Jenkins jobs via Maven. Much of the information needed by Jenkins when creating a job is already in the Maven pom. The SCM information and CI url are present. Jenkins jobs also typically have names that reflect the groupId, artifactId, and version in some manner. This plugin automates the process of creating Jenkins jobs by harvesting information from the POM to create XML config files in the format Jenkins needs. The Jenkins CLI API is then used to create, update, read, and delete Jenkins jobs on the CI server. If your Jenkins instance requires authentication, add your public key to your user account on the Jenkins server.

There is a newer version: 1.2.8
Show newest version
/**
 * Copyright 2011-2013 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.maven.plugins.jenkins;

import java.io.File;
import java.util.List;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.project.MavenProject;
import org.kuali.maven.plugins.jenkins.helper.JenkinsHelper;

/**
 *
 */
public abstract class BaseMojo extends AbstractMojo {
	JenkinsHelper helper = new JenkinsHelper();

	/**
	 * The Maven project object
	 *
	 * @parameter expression="${project}"
	 * @readonly
	 */
	private MavenProject project;

	/**
	 * The plugin dependencies.
	 *
	 * @parameter expression="${plugin.artifacts}"
	 * @required
	 * @readonly
	 */
	private List pluginArtifacts;

	/**
	 * The fully qualified url of a Jenkins instance to connect to. This is required if sshEnabled is false.
	 *
	 * @parameter expression="${jenkins.url}" default-value="${project.ciManagement.url}"
	 */
	private String url;

	/**
	 * The DNS name of a Jenkins instance to connect to (used when ssh is enabled)
	 *
	 * @parameter expression="${jenkins.hostname}"
	 */
	private String hostname;

	/**
	 * Username for an account on the Jenkins instance (used when ssh is enabled)
	 *
	 * @parameter expression="${jenkins.username}" default-value="${user.name}"
	 */
	private String username;

	/**
	 * The format for timestamp displays
	 *
	 * @parameter expression="${jenkins.timestampFormat}" default-value="yyyy-MM-dd HH:mm:ss z"
	 * @required
	 */
	private String timestampFormat;

	/**
	 * The working directory for the plugin
	 *
	 * @parameter expression="${jenkins.workingDir}" default-value="${project.build.directory}/jenkins"
	 * @required
	 */
	private File workingDir;

	/**
	 * If true, the build will fail the first time Jenkins CLI encounters an issue. When false, mojo's that issue multiple CLI requests,
	 * will proceed through their list of requests and then fail at the end if an issue was encountered along the way.
	 *
	 * @parameter expression="${jenkins.stopOnError}" default-value="false"
	 * @required
	 */
	private boolean stopOnError;

	/**
	 * If true, the version of the Maven project is not included in the job name
	 *
	 * @parameter expression="${jenkins.excludeVersion}" default-value="true"
	 * @required
	 */
	private boolean excludeVersion;

	/**
	 * If true, Maven will issue Jenkins CLI commands over ssh instead of via java -jar jenkins-cli.jar
	 *
	 * @parameter expression="${jenkins.sshEnabled}" default-value="true"
	 */
	private boolean sshEnabled;

	/**
	 * If true, ssh is executed with -v. Useful for troubleshooting ssh issues
	 *
	 * @parameter expression="${jenkins.sshVerbose}" default-value="false"
	 */
	private boolean sshVerbose;

	/**
	 * For ssh enabled calls, this is the port the Jenkins server has been configured to listen on for SSH connections.
	 *
	 * @parameter expression="${jenkins.sshPort}" default-value="45358"
	 */
	private int sshPort;

	/**
	 * If true, the Maven build will fail if Jenkins CLI returns a non-zero exit value, otherwise the Maven build will continue
	 *
	 * @parameter expression="${jenkins.failOnError}" default-value="true"
	 * @required
	 */
	private boolean failOnError;

	/**
	 * Optional List of custom Style xml templates. Custom style templates are supplied to the plugin like this:
	 *
	 * 
	 * <configuration>
	 *   <styles>
	 *     <style>
	 *       <name>my-custom-style</name>
	 *       <template>classpath:org/foo/bar/my-custom-style.xml</template>
	 *     </style>
	 *   </styles>
	 * </configuration>
	 * 
* * @parameter expression="${jenkins.styles}" */ private List