Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into atual/incr
Browse files Browse the repository at this point in the history
* origin/master:
  Bump `hashicorp-tools` docker image to 0.5.163 (jenkins-infra#659)
  fix(buildPlugin) ensure the custom label is passed to node when adding custom platform (jenkins-infra#658)
  feat(buildPluginWithGradle) Add quality checks (jenkins-infra#652)
  hotfix(terraform) add spot toleration
  hotfix(terraform) add nodeselector
  Update updatecli version to v0.49.2 (jenkins-infra#657)
  fix(terraform): add toleration to use infracipool (jenkins-infra#655)
  Bump `hashicorp-tools` docker image to 0.5.162 (jenkins-infra#651)
  • Loading branch information
alextu committed May 2, 2023
2 parents 7fac072 + 538e99c commit a0b52a8
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/updatecli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v3
- name: Install updatecli CLI
env:
UPDATECLI_VERSION: "v0.48.1"
UPDATECLI_VERSION: "v0.49.2"
run: |
curl --silent --location --show-error --output /tmp/updatecli.tgz \
"https://github.com/updatecli/updatecli/releases/download/${UPDATECLI_VERSION}/updatecli_$(uname -s)_$(uname -m).tar.gz"
Expand Down
5 changes: 5 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ buildPluginWithGradle(/*...*/, configurations: [

* `tests`: (default: `null`) - a map of parameters to run tests during the build
** `skip` - If `true`, skip all the tests.
* `jacoco`: (default: `null`) - a map of parameters to change the default configuration of the `recordCoverage` step of the https://github.com/jenkinsci/code-coverage-api-plugin[Code Coverage Plugin]. This step is called after a plugin build to record the code coverage results of JaCoCo. See https://www.jenkins.io/doc/pipeline/steps/code-coverage-api/#recordcoverage-record-code-coverage-results[recordCoverage step documentation] for a list of available configuration parameters.
* `spotbugs`, `checkstyle`: (default: `null`) - a map of parameters to archive SpotBugs or CheckStyle warnings, respectively.
These values can replace or amend the default configuration for the `recordIssues` step of the https://github.com/jenkinsci/warnings-ng-plugin[Warnings NG Plugin].
See https://github.com/jenkinsci/warnings-ng-plugin/blob/master/doc/Documentation.md#configuration[Warnings NG Plugin documentation]
for a list of available configuration parameters.
* `timeout`: (default: `60`) - the number of minutes for build timeout, cannot be bigger than 180, i.e. 3 hours.
* `incrementals`: (default: `false`) - activates incremental versions publication. It requires Gradle JPI Plugin 0.49.0 and to not
have set a version in `build.gradle` (having it in gradle.properties is fine), so it can be overridden.
Expand Down
36 changes: 32 additions & 4 deletions test/groovy/BuildPluginStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,45 @@ class BuildPluginStepTests extends BaseTest {
// when running without any parameters
script.call([:])
printCallStack()
// then it runs in a linux node
assertTrue(assertMethodCallContainsPattern('node', 'linux'))
// then it runs in a windows node
assertTrue(assertMethodCallContainsPattern('node', 'windows'))
// then it runs a stage in a linux VM by default
assertTrue(assertMethodCallContainsPattern('node', 'vm && linux'))
// then it runs a stage in a Windows VM by default
assertTrue(assertMethodCallContainsPattern('node', 'docker-windows'))
// then it runs the junit step by default
assertTrue(assertMethodCall('junit'))
// then it runs the junit step with the maven test format
assertTrue(assertMethodCallContainsPattern('junit', '**/target/surefire-reports/**/*.xml,**/target/failsafe-reports/**/*.xml'))
assertJobStatusSuccess()
}

@Test
void test_buildPlugin_with_container_agents() throws Exception {
def script = loadScript(scriptName)
// when running with useContainerAgent set to true
script.call([useContainerAgent: true])
printCallStack()
// then it runs a stage in a linux container by default
assertTrue(assertMethodCallContainsPattern('node', 'maven'))
// then it runs a stage in a Windows container by default
assertTrue(assertMethodCallContainsPattern('node', 'maven-windows'))
assertJobStatusSuccess()
}

@Test
void test_buildPlugin_with_customplatforms() throws Exception {
def script = loadScript(scriptName)
// when running with useContainerAgent set to true
script.call(platforms: ['openbsd', 'maven-windows-experimental'])
printCallStack()
// then it runs a stage in an openbsd node with a warning message
assertTrue(assertMethodCallContainsPattern('node', 'openbsd'))
assertTrue(assertMethodCallContainsPattern('echo', 'WARNING: Unknown Virtual Machine platform \'openbsd\''))
// then it runs a stage in a maven-windows-experimental node with a warning message
assertTrue(assertMethodCallContainsPattern('node', 'maven-windows-experimental'))
assertTrue(assertMethodCallContainsPattern('echo', 'WARNING: Unknown Virtual Machine platform \'maven-windows-experimental\''))
assertJobStatusSuccess()
}

@Test
void test_buildPlugin_with_timeout() throws Exception {
def script = loadScript(scriptName)
Expand Down
72 changes: 72 additions & 0 deletions test/groovy/BuildPluginWithGradleStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,76 @@ class BuildPluginWithGradleStepTests extends BaseTest {

assertFalse(assertMethodCallContainsPattern('fingerprint', '**/*-rc*.*/*-rc*.*'))
}

@Test
void test_buildPluginWithGradle_with_warnings_ng() throws Exception {
def script = loadScript(scriptName)
script.call()
printCallStack()

assertTrue(assertMethodCall('java'))
assertTrue(assertMethodCall('javaDoc'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{enabledForFailure=true, tools=[java, javadoc], filters=[true], sourceCodeEncoding=UTF-8, skipBlames=true, trendChartType=TOOLS_ONLY}'))

assertTrue(assertMethodCall('spotBugs'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=spotbugs, sourceCodeEncoding=UTF-8, skipBlames=true, trendChartType=TOOLS_ONLY, qualityGates=[{threshold=1, type=NEW, unstable=true}]}'))

assertTrue(assertMethodCall('checkStyle'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=checkstyle, sourceCodeEncoding=UTF-8, skipBlames=true, trendChartType=TOOLS_ONLY, qualityGates=[{threshold=1, type=TOTAL, unstable=true}]}'))

assertTrue(assertMethodCallContainsPattern('taskScanner', '{includePattern=**/*.java, excludePattern=**/build/**, highTags=FIXME, normalTags=TODO}'))
assertTrue(assertMethodCallContainsPattern('recordIssues', '{enabledForFailure=true, tool=tasks, sourceCodeEncoding=UTF-8, skipBlames=true, trendChartType=NONE}'))
}

@Test
void test_buildPluginWithGradle_with_warnings_ng_and_thresholds() throws Exception {
def script = loadScript(scriptName)
script.call(spotbugs: [
qualityGates : [
[threshold: 3, type: 'TOTAL', unstable: true],
[threshold: 4, type: 'NEW', unstable: true],
],
sourceCodeEncoding: 'UTF-16'])
printCallStack()

assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=spotbugs, sourceCodeEncoding=UTF-16, skipBlames=true, trendChartType=TOOLS_ONLY, qualityGates=[{threshold=3, type=TOTAL, unstable=true}, {threshold=4, type=NEW, unstable=true}]}'))
}

@Test
void test_buildPluginWithGradle_with_warnings_ng_and_checkstyle() throws Exception {
def script = loadScript(scriptName)
script.call(checkstyle: [
qualityGates: [
[threshold: 3, type: 'TOTAL', unstable: true],
[threshold: 4, type: 'NEW', unstable: true],
],
filters : '[includeFile(\'MyFile.*.java\'), excludeCategory(\'WHITESPACE\')]'])
printCallStack()

assertTrue(assertMethodCallContainsPattern('recordIssues', '{tool=checkstyle, sourceCodeEncoding=UTF-8, skipBlames=true, trendChartType=TOOLS_ONLY, qualityGates=[{threshold=3, type=TOTAL, unstable=true}, {threshold=4, type=NEW, unstable=true}], filters=[includeFile(\'MyFile.*.java\'), excludeCategory(\'WHITESPACE\')]}'))
}

@Test
void test_buildPluginWithGradle_with_record_coverage_defaults() throws Exception {
def script = loadScript(scriptName)
script.call()
printCallStack()

assertTrue(assertMethodCall('recordCoverage'))
assertDefaultRecordCoverageWithJaCoCo()
}

private assertDefaultRecordCoverageWithJaCoCo() {
assertTrue(assertMethodCallContainsPattern('recordCoverage', '{tools=[{parser=JACOCO, pattern=**/build/reports/jacoco/**/*.xml}], sourceCodeRetention=MODIFIED}'))
}

@Test
void test_buildPluginWithGradle_with_record_coverage_custom() throws Exception {
def script = loadScript(scriptName)
script.call(jacoco: [sourceCodeRetention: 'EVERY_BUILD', sourceDirectories: [[path: 'plugin/src/main/java']]])
printCallStack()

assertTrue(assertMethodCall('recordCoverage'))
assertTrue(assertMethodCallContainsPattern('recordCoverage', '{tools=[{parser=JACOCO, pattern=**/build/reports/jacoco/**/*.xml}], sourceCodeRetention=EVERY_BUILD, sourceDirectories=[{path=plugin/src/main/java}]}'))
}
}
4 changes: 2 additions & 2 deletions vars/buildPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def call(Map params = [:]) {
label = 'vm && linux'
break
default:
echo "WARNING: Unknown platform '${platform}'. Agent label set to fallback value 'linux'"
label = 'linux'
echo "WARNING: Unknown Virtual Machine platform '${platform}'. Set useContainerAgent to 'true' unless you want to be in uncharted territory."
label = platform
}
}

Expand Down
55 changes: 53 additions & 2 deletions vars/buildPluginWithGradle.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,62 @@ def call(Map params = [:]) {
}

stage("Archive (${stageIdentifier})") {
//TODO(oleg-nenashev): Add static analysis results publishing like in buildPlugin() for Maven

if (failFast && currentBuild.result == 'UNSTABLE') {
error 'There were test failures; halting early'
}
echo "Recording static analysis results on '${stageIdentifier}'"

recordIssues(
enabledForFailure: true,
tools: [java(), javaDoc()],
filters: [excludeFile('.*Assert.java')],
sourceCodeEncoding: 'UTF-8',
skipBlames: true,
trendChartType: 'TOOLS_ONLY'
)

// Default configuration for SpotBugs can be overwritten using a `spotbugs`, `checkstyle', etc. parameter (map).
// Configuration see: https://github.com/jenkinsci/warnings-ng-plugin/blob/master/doc/Documentation.md#configuration
Map spotbugsArguments = [tool: spotBugs(pattern: '**/build/reports/spotbugs/*.xml'),
sourceCodeEncoding: 'UTF-8',
skipBlames: true,
trendChartType: 'TOOLS_ONLY',
qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]]
if (params?.spotbugs) {
spotbugsArguments.putAll(params.spotbugs as Map)
}
recordIssues spotbugsArguments

Map checkstyleArguments = [tool: checkStyle(pattern: '**/build/reports/checkstyle/*.xml'),
sourceCodeEncoding: 'UTF-8',
skipBlames: true,
trendChartType: 'TOOLS_ONLY',
qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]]]
if (params?.checkstyle) {
checkstyleArguments.putAll(params.checkstyle as Map)
}
recordIssues checkstyleArguments

Map jacocoArguments = [tools: [[parser: 'JACOCO', pattern: '**/build/reports/jacoco/**/*.xml']], sourceCodeRetention: 'MODIFIED']
if (params?.jacoco) {
jacocoArguments.putAll(params.jacoco as Map)
}
recordCoverage jacocoArguments


recordIssues(
enabledForFailure: true, tool: taskScanner(
includePattern:'**/*.java',
excludePattern:'**/build/**',
highTags:'FIXME',
normalTags:'TODO'),
sourceCodeEncoding: 'UTF-8',
skipBlames: true,
trendChartType: 'NONE'
)
if (failFast && currentBuild.result == 'UNSTABLE') {
error 'Static analysis quality gates not passed; halting early'
}

if (doArchiveArtifacts) {
if (changelist) {
Expand Down
2 changes: 1 addition & 1 deletion vars/buildPluginWithGradle.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>
The implementation follows the standard build/test/archive pattern.
Note that the Gradle flow for Jenkins plugins offers less functionality than the Maven flow,
some key features are not supported: Incrementals - JEP-305, standard static analysis flows, etc.
some key features are not supported: Incrementals - JEP-305, etc.
The current version also does not allow configuring the <code>jenkinsVersion</code>.
</p>

Expand Down
14 changes: 13 additions & 1 deletion vars/terraform.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def call(userConfig = [:]) {
stagingCredentials: [], // No custom secrets for staging by default
productionCredentials: [], // No custom secrets for production by default
productionBranch: 'main', // Defaults to the principal branch
agentContainerImage: 'jenkinsciinfra/hashicorp-tools:0.5.161', // Version managed by updatecli
agentContainerImage: 'jenkinsciinfra/hashicorp-tools:0.5.163', // Version managed by updatecli
runTests: false, // Executes the tests provided by the "calling" project, which should provide a tests/Makefile
runCommonTests: true, // Executes the default test suite from the shared tools repository (terratest)
]
Expand Down Expand Up @@ -147,6 +147,18 @@ def agentTemplate(containerImage, body) {
kind: Pod
spec:
automountServiceAccountToken: false
nodeSelector:
kubernetes.azure.com/agentpool: infracipool
kubernetes.io/os: linux
tolerations:
- key: "jenkins"
operator: "Equal"
value: "infra.ci.jenkins.io"
effect: "NoSchedule"
- key: "kubernetes.azure.com/scalesetpriority"
operator: "Equal"
value: "spot"
effect: "NoSchedule"
resources:
limits:
cpu: 2
Expand Down

0 comments on commit a0b52a8

Please sign in to comment.