Skip to content

Commit

Permalink
Merge branch 'master' into gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev authored Aug 15, 2019
2 parents 9d11bbc + 53f30fa commit 6ab6b00
Show file tree
Hide file tree
Showing 13 changed files with 1,027 additions and 132 deletions.
4 changes: 4 additions & 0 deletions .github/release-drafter.yml
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
*.sw*
build/
target
target/

# IDEA
.idea

# Visual Studio Code
.project
Expand Down
21 changes: 21 additions & 0 deletions Jenkinsfile
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')
}
}
}
}
}
33 changes: 31 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ buildPlugin()
==== Optional arguments

* `repo` (default: `null` inherit from Multibranch) - custom Git repository to check out
* `useAci` (default: `false`) - uses link:https://azure.microsoft.com/en-us/services/container-instances/[Azure Container Instances] for build instead of link:https://azure.microsoft.com/en-us/services/virtual-machines/[Azure Virtual Machines].
* `failFast` (default: `true`) - instruct Maven tests to fail fast
* `platforms` (default: `['linux', 'windows']`) - Labels matching platforms to
execute the steps against in parallel
Expand All @@ -31,9 +32,10 @@ buildPlugin()
* `jenkinsVersions`: (default: `[null]`) - a matrix of Jenkins baseline versions to build/test against in parallel (null means default,
only available for Maven projects)
* `configurations`: An alternative way to specify `platforms`, `jdkVersions` and `jenkinsVersions` (that can not be combined
with any of them). Those options will run the build for all combinations of their values. While that is desirable in
with any of them).
** Those options will run the build for all combinations of their values. While that is desirable in
many cases, `configurations` permit to provide a specific combinations of label and java/jenkins versions to use:

[source,groovy]
----
buildPlugin(/*...*/, configurations: [
Expand All @@ -42,6 +44,17 @@ buildPlugin(/*...*/, configurations: [
[ platform: "linux", jdk: "11", jenkins: "2.150", javaLevel: 8 ]
])
----

** It is also possible to use a `buildPlugin.recommendedConfigurations()` method to get recommended configurations for testing.
Note that the recommended configuration may change over time,
and hence your CI may break if the new recommended configuration is not compatible

[source,groovy]
----
buildPlugin(/*...*/, configurations: buildPlugin.recommendedConfigurations())
----


* `tests`: (default: `null`) - a map of parameters to run tests during the build
** `skip` - If `true`, skipp all the tests by setting the `-skipTests` profile.
It will also skip FindBugs in modern Plugin POMs.
Expand Down Expand Up @@ -345,6 +358,22 @@ pct: "default"

*Please note that a blank metadata file will result in an error*

=== runBenchmarks

Runs JMH benchmarks and archives benchmark reports on `highmem` nodes.

Supported parameters:

`artifacts`::
(Optional) If `artifacts` is not null, invokes `archiveArtifacts` with the given string value.


===== Example
[source, groovy]
----
runBenchmarks('jmh-report.json')
----

=== Design documents for runATH and runPCT

The design and some more details about the runATH and runPCT steps can be found link:https://wiki.jenkins.io/display/JENKINS/runATH+and+runPCT+step+design[here]
102 changes: 102 additions & 0 deletions pom.xml
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>
171 changes: 171 additions & 0 deletions src/test/groovy/CustomWARPackagerStepTests.groovy
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()
}

}
Loading

0 comments on commit 6ab6b00

Please sign in to comment.