-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into gitignore
- Loading branch information
Showing
13 changed files
with
1,027 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# See https://github.com/jenkinsci/.github/blob/master/.github/release-drafter.adoc | ||
_extends: jenkinsci/.github | ||
# Semantic versioning: https://semver.org/ | ||
version-template: $MAJOR.$MINOR.$PATCH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
*.sw* | ||
build/ | ||
target | ||
target/ | ||
|
||
# IDEA | ||
.idea | ||
|
||
# Visual Studio Code | ||
.project | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env groovy | ||
pipeline { | ||
agent { | ||
label "maven" | ||
} | ||
options { | ||
timestamps() | ||
} | ||
stages { | ||
stage('Test') { | ||
steps { | ||
sh 'mvn -B clean test' | ||
} | ||
post { | ||
always { | ||
junit(keepLongStdio: true, testResults: 'target/surefire-reports/TEST-*.xml') | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>io.jenkins.infra</groupId> | ||
<artifactId>pipeline-library</artifactId> | ||
<version>0.0.1</version> | ||
<name>Jenkins Pipeline Shared Library</name> | ||
<description>Pipeline Shared Library containing utility steps.</description> | ||
<url>https://github.com/jenkins-infra/pipeline-library</url> | ||
|
||
<licenses> | ||
<license> | ||
<name>MIT License</name> | ||
<url>http://opensource.org/licenses/MIT</url> | ||
</license> | ||
</licenses> | ||
|
||
<scm> | ||
<connection>scm:git:git://github.com/jenkins-infra/pipeline-library.git</connection> | ||
<developerConnection>scm:git:ssh://[email protected]/jenkins-infra/pipeline-library.git</developerConnection> | ||
</scm> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<!-- Dependency versions --> | ||
<groovy.version>2.4.17</groovy.version> | ||
<junit.version>4.12</junit.version> | ||
<jenkins-pipeline-unit.version>1.1</jenkins-pipeline-unit.version> | ||
<groovy-eclipse-compiler.version>3.4.0-01</groovy-eclipse-compiler.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.codehaus.groovy</groupId> | ||
<artifactId>groovy-all</artifactId> | ||
<version>${groovy.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.lesfurets</groupId> | ||
<artifactId>jenkins-pipeline-unit</artifactId> | ||
<version>${jenkins-pipeline-unit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.yaml</groupId> | ||
<artifactId>snakeyaml</artifactId> | ||
<version>1.21</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<testSourceDirectory>src/test/groovy</testSourceDirectory> | ||
<resources> | ||
<resource> | ||
<directory>resources</directory> | ||
</resource> | ||
</resources> | ||
<scriptSourceDirectory>vars</scriptSourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.groovy</groupId> | ||
<artifactId>groovy-eclipse-compiler</artifactId> | ||
<version>${groovy-eclipse-compiler.version}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<compilerId>groovy-eclipse-compiler</compilerId> | ||
</configuration> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.codehaus.groovy</groupId> | ||
<artifactId>groovy-eclipse-compiler</artifactId> | ||
<version>${groovy-eclipse-compiler.version}</version> | ||
</dependency> | ||
<!-- for 2.8.0-01 and later you must have an explicit dependency on groovy-eclipse-batch --> | ||
<dependency> | ||
<groupId>org.codehaus.groovy</groupId> | ||
<artifactId>groovy-eclipse-batch</artifactId> | ||
<version>2.5.7-01</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.0.0-M3</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import com.lesfurets.jenkins.unit.BasePipelineTest | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.yaml.snakeyaml.Yaml | ||
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString | ||
import static org.junit.Assert.assertTrue | ||
|
||
class CustomWARPackagerStepTests extends BasePipelineTest { | ||
static final String scriptName = 'vars/customWARPackager.groovy' | ||
Map env = [:] | ||
|
||
static final String without_packaging_metadata = ''' | ||
bar: true | ||
''' | ||
|
||
static final String without_packaging_config_metadata = ''' | ||
packaging: | ||
bom: true | ||
environment: true | ||
jdk: 7 | ||
cwpVersion: "1.2.3" | ||
archiveArtifacts: false | ||
installArtifacts: false | ||
''' | ||
|
||
static final String without_bom_config_metadata = ''' | ||
packaging: | ||
config: true | ||
environment: true | ||
jdk: 7 | ||
cwpVersion: "1.2.3" | ||
archiveArtifacts: false | ||
installArtifacts: false | ||
metadata: | ||
config: true | ||
''' | ||
|
||
static final String default_config_metadata = ''' | ||
packaging: | ||
config: true | ||
environment: true | ||
jdk: 7 | ||
cwpVersion: "1.2.3" | ||
archiveArtifacts: false | ||
installArtifacts: false | ||
metadata: | ||
labels: | ||
version: "foo" | ||
artifactId: "barId" | ||
''' | ||
|
||
/** | ||
* Mock Infra step | ||
*/ | ||
class Infra implements Serializable { | ||
public String retrieveMavenSettingsFile(String location) { return location } | ||
public String runWithMaven(String cmd) { return cmd } | ||
public String runMaven(mvn, jdk, foo, settings) { return 'OK' } | ||
} | ||
|
||
@Override | ||
@Before | ||
void setUp() throws Exception { | ||
super.setUp() | ||
|
||
binding.setProperty('infra', new Infra()) | ||
binding.setVariable('env', env) | ||
|
||
helper.registerAllowedMethod('archiveArtifacts', [Map.class], { m -> m }) | ||
helper.registerAllowedMethod('echo', [String.class], { s -> s }) | ||
helper.registerAllowedMethod('error', [String.class], {s -> | ||
updateBuildStatus('FAILURE') | ||
throw new Exception(s) | ||
}) | ||
helper.registerAllowedMethod('findFiles', [Map.class], { String[] files = ["bom.yml", "d1/bom.yml"] }) | ||
helper.registerAllowedMethod('pwd', [], { '/foo' }) | ||
helper.registerAllowedMethod('pwd', [Map.class], { '/bar' }) | ||
helper.registerAllowedMethod('readYaml', [Map.class], { | ||
Yaml yaml = new Yaml() | ||
return yaml.load(default_config_metadata) | ||
}) | ||
helper.registerAllowedMethod('sh', [String.class], { s -> s }) | ||
helper.registerAllowedMethod('writeYaml', [Map.class], { }) | ||
} | ||
|
||
@Test | ||
void test_without_packaging() throws Exception { | ||
def script = loadScript(scriptName) | ||
helper.registerAllowedMethod('readYaml', [Map.class], { | ||
Yaml yaml = new Yaml() | ||
return yaml.load(without_packaging_metadata) | ||
}) | ||
// when running without metadata.packaging | ||
try { | ||
script.build('metadataFile', 'outputWAR', 'outputBOM', 'settings') | ||
} catch(e){ | ||
//NOOP | ||
} | ||
printCallStack() | ||
// then an error is thrown | ||
assertTrue(helper.callStack.findAll { call -> | ||
call.methodName == 'error' | ||
}.any { call -> | ||
callArgsToString(call).contains("No 'packaging' section in the metadata file metadataFile") | ||
}) | ||
assertJobStatusFailure() | ||
} | ||
|
||
@Test | ||
void test_without_packaging_config() throws Exception { | ||
def script = loadScript(scriptName) | ||
helper.registerAllowedMethod('readYaml', [Map.class], { | ||
Yaml yaml = new Yaml() | ||
return yaml.load(without_packaging_config_metadata) | ||
}) | ||
// when running without metadata.packaging | ||
try { | ||
script.build('metadataFile', 'outputWAR', 'outputBOM', 'settings') | ||
} catch(e){ | ||
//NOOP | ||
} | ||
printCallStack() | ||
// then an error is thrown | ||
assertTrue(helper.callStack.findAll { call -> | ||
call.methodName == 'error' | ||
}.any { call -> | ||
callArgsToString(call).contains("packaging.config or packaging.configFile must be defined") | ||
}) | ||
assertJobStatusFailure() | ||
} | ||
|
||
@Test | ||
void test_without_bom_config() throws Exception { | ||
def script = loadScript(scriptName) | ||
helper.registerAllowedMethod('readYaml', [Map.class], { m -> | ||
Yaml yaml = new Yaml() | ||
return yaml.load(without_bom_config_metadata) | ||
}) | ||
script.build('metadataFile', 'outputWAR', 'outputBOM', 'settings') | ||
printCallStack() | ||
assertTrue(helper.callStack.findAll { call -> | ||
call.methodName == 'echo' | ||
}.any { call -> | ||
callArgsToString(call).contains("BOM file is not explicitly defined, but there is bom.yml in the root. Using it") | ||
}) | ||
assertJobStatusSuccess() | ||
} | ||
|
||
@Test | ||
void test_default_config() throws Exception { | ||
def script = loadScript(scriptName) | ||
script.build('metadataFile', 'outputWAR', 'outputBOM', 'settings') | ||
printCallStack() | ||
|
||
// then the war file with the artifact id and label from the metadata is copied | ||
assertTrue(helper.callStack.findAll { call -> | ||
call.methodName == 'sh' | ||
}.any { call -> | ||
callArgsToString(call).contains('cp barId-foo.war') | ||
}) | ||
|
||
// then the yaml file with the artifact id and label from the metadata is copied | ||
assertTrue(helper.callStack.findAll { call -> | ||
call.methodName == 'sh' | ||
}.any { call -> | ||
callArgsToString(call).contains('cp barId-foo.bom.yml') | ||
}) | ||
assertJobStatusSuccess() | ||
} | ||
|
||
} |
Oops, something went wrong.