Skip to content
Permalink
Browse files

[JENKINS-30904] Added Job DSL support

  • Loading branch information...
praqma-thi authored and MadsNielsen committed Sep 8, 2015
1 parent 1ef6728 commit 700410c7b021c1aab7a0c0fa3d721bb3cea9380c
@@ -386,6 +386,13 @@
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>job-dsl</artifactId>
<version>1.37</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>net.praqma</groupId>
<artifactId>cool</artifactId>
@@ -0,0 +1,46 @@
package net.praqma.jenkins.configrotator;

import java.util.ArrayList;
import java.util.List;
import javaposse.jobdsl.dsl.Context;
import static javaposse.jobdsl.plugin.ContextExtensionPoint.executeInContext;
import net.praqma.clearcase.PVob;
import net.praqma.jenkins.configrotator.scm.clearcaseucm.ClearCaseUCMTarget;

class ClearCaseJobDslContext implements Context {

PVob projectVob;

public void projectVob(String name) {
projectVob = new PVob(name);
}

boolean globalData;

public void globalData() {
globalData = true;
}

public void globalData(boolean value) {
globalData = value;
}

boolean useNewest;

public void useNewest() {
useNewest = true;
}

public void useNewest(boolean value) {
useNewest = value;
}

List<ClearCaseUCMTarget> targets = new ArrayList<ClearCaseUCMTarget>();

public void target(Runnable closure) {
ClearCaseTargetJobDslContext context = new ClearCaseTargetJobDslContext();
executeInContext(closure, context);

targets.add(new ClearCaseUCMTarget(context.baseline, context.promotionLevel, context.fixed));
}
}
@@ -0,0 +1,29 @@
package net.praqma.jenkins.configrotator;

import javaposse.jobdsl.dsl.Context;
import net.praqma.clearcase.ucm.entities.Project.PromotionLevel;

class ClearCaseTargetJobDslContext implements Context {

String baseline;

public void baseline(String value) {
baseline = value;
}

PromotionLevel promotionLevel = PromotionLevel.INITIAL;

public void promotionLevel(String value) {
promotionLevel = PromotionLevel.valueOf(value);
}

boolean fixed = false;

public void fixed() {
fixed = true;
}

public void fixed(boolean value) {
fixed = value;
}
}
@@ -0,0 +1,159 @@
package net.praqma.jenkins.configrotator;

import hudson.Extension;
import java.util.HashSet;
import java.util.Set;
import static javaposse.jobdsl.dsl.Preconditions.checkArgument;
import javaposse.jobdsl.dsl.RequiresPlugin;
import javaposse.jobdsl.dsl.helpers.ScmContext;
import javaposse.jobdsl.dsl.helpers.publisher.PublisherContext;
import javaposse.jobdsl.plugin.ContextExtensionPoint;
import javaposse.jobdsl.plugin.DslExtensionMethod;
import net.praqma.jenkins.configrotator.scm.clearcaseucm.ClearCaseUCM;
import net.praqma.jenkins.configrotator.scm.git.Git;

/*
scm can be: 'git' or 'clearCase'.
Configuration differs depending on choice.
GIT
```
job{
scm{
configRotator('git'){
target{
name (String name)
repository (String repo)
branch (String branch)
commit (String commit)
fixed (boolean fixed = true) // Defaults to false
}
}
}
publishers{
configRotatorPublisher()
}
}
```
For example:
```
job('letters_GEN'){
scm{
configRotator('git'){
target{
name 'capital'
repository 'https://github.com/praqma-test/capital-letters.git'
branch 'master'
commit '522e47d6bc88948d0182902badde8c9a0eb14a82'
fixed false
}
target{
name 'lower'
repository 'https://github.com/praqma-test/lower-letters.git'
branch 'master'
commit '85c76dd6a4037085a5b0f6c986e392d4386395cd'
fixed false
}
}
}
publishers{
configRotatorPublisher()
}
}
```
CLEARCASE
```
job{
scm{
configRotator('clearCase'){
projectVob (String pvob)
useNewest (boolean useNewest = true) // Defaults to false
globalData (boolean contributeDataGlobally = true) // Defaults to false
target{
baseline (String baseline)
promotionLevel (String promotionLevel) // Can be: INITIAL, BUILT, TESTED, RELEASED or REJECTED. Defaults to INITIAL.
fixed (boolean fixed = true) // Defaults to false
}
}
}
publishers{
configRotatorPublisher()
}
}
```
For example:
```
job('crot_GEN'){
scm{
configRotator('clearCase'){
projectVob '\\crot_PVOB'
useNewest()
globalData()
target{
baseline 'client-1@\\crot_PVOB'
promotionLevel 'INITIAL'
fixed false
}
target{
baseline 'model-1@\\crot_PVOB'
promotionLevel 'INITIAL'
fixed false
}
}
}
publishers{
configRotatorPublisher()
}
}
```
*/

@Extension(optional = true)
public class ConfigRotatorJobDslExtension extends ContextExtensionPoint {

private final Set<String> SCM = new HashSet<String>() {
{
add("git");
add("clearCase");
}
};

@RequiresPlugin(id = "config-rotator", minimumVersion = "1.2.2")
@DslExtensionMethod(context = PublisherContext.class)
public Object configRotatorPublisher() {
return new ConfigurationRotatorPublisher();
}

@RequiresPlugin(id = "config-rotator", minimumVersion = "1.2.2")
@DslExtensionMethod(context = ScmContext.class)
public Object configRotator(String scm, Runnable closure) {
checkArgument(SCM.contains(scm), "scm must be one of: " + SCM.toString());

AbstractConfigurationRotatorSCM acrs = null;

if (scm.equals("git")) {
GitJobDslContext context = new GitJobDslContext();
executeInContext(closure, context);
Git git = new Git();
git.setTargets(context.targets);
git.setUseNewest(false);
acrs = git;
} else if (scm.equals("clearCase")) {
ClearCaseJobDslContext context = new ClearCaseJobDslContext();
executeInContext(closure, context);
ClearCaseUCM clearCase = new ClearCaseUCM(context.projectVob);
clearCase.setTargets(context.targets);
clearCase.setContribute(context.globalData);
clearCase.setUseNewest(context.useNewest);
acrs = clearCase;
}

return new ConfigurationRotator(acrs);
}
}
@@ -0,0 +1,20 @@
package net.praqma.jenkins.configrotator;

import java.util.ArrayList;
import java.util.List;
import javaposse.jobdsl.dsl.Context;
import static javaposse.jobdsl.plugin.ContextExtensionPoint.executeInContext;
import net.praqma.jenkins.configrotator.scm.git.GitTarget;

class GitJobDslContext implements Context {

List<GitTarget> targets = new ArrayList<GitTarget>();

public void target(Runnable closure) {
GitTargetJobDslContext context = new GitTargetJobDslContext();
executeInContext(closure, context);

targets.add(new GitTarget(context.name, context.repository, context.branch, context.commit, context.fixed));
}

}
@@ -0,0 +1,41 @@
package net.praqma.jenkins.configrotator;

import javaposse.jobdsl.dsl.Context;

class GitTargetJobDslContext implements Context {

String name;

public void name(String value) {
name = value;
}

String repository;

public void repository(String value) {
repository = value;
}

String branch;

public void branch(String value) {
branch = value;
}

String commit;

public void commit(String value) {
commit = value;
}

boolean fixed = false;

public void fixed() {
fixed = true;
}

public void fixed(boolean value) {
fixed = value;
}

}

0 comments on commit 700410c

Please sign in to comment.
You can’t perform that action at this time.