Skip to content

Commit

Permalink
Merge branch 'ZNTA-2234-codecov' into test-ZNTA-2234
Browse files Browse the repository at this point in the history
Conflicts:
	Jenkinsfile
	build-tools/src/test/java/TestJenkinsfile.java
  • Loading branch information
definite committed Oct 24, 2017
2 parents 686ce62 + a144d06 commit 01ac9eb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
39 changes: 25 additions & 14 deletions Jenkinsfile
Expand Up @@ -17,6 +17,7 @@ public static final String PIPELINE_LIBRARY_BRANCH = 'ZNTA-2234-tag'
@Library('zanata-pipeline-library@ZNTA-2234-tag')
import org.zanata.jenkins.Notifier
import org.zanata.jenkins.PullRequests
import org.zanata.jenkins.ScmGit
import static org.zanata.jenkins.Reporting.codecov
import static org.zanata.jenkins.StackTraces.getStackTrace

Expand All @@ -27,12 +28,15 @@ milestone()

PullRequests.ensureJobDescription(env, manager, steps)

// initialiser must be run separately (bindings not available during compilation phase)
@Field
def pipelineLibraryScmGit

@Field
def mainScmGit

@Field
def notify
// initialiser must be run separately (bindings not available during compilation phase)
notify = new Notifier(env, steps, currentBuild,
PROJ_URL, 'Jenkinsfile', PIPELINE_LIBRARY_BRANCH,
)

// we can't set these values yet, because we need a node to look at the environment
@Field
Expand All @@ -48,6 +52,13 @@ def jobName
// we need a node to access env.DEFAULT_NODE.
node {
echo "running on node ${env.NODE_NAME}"
pipelineLibraryScmGit = new ScmGit(env, steps, 'https://github.com/zanata/zanata-pipeline-library')
pipelineLibraryScmGit.init(PIPELINE_LIBRARY_BRANCH)
mainScmGit = new ScmGit(env, steps, PROJ_URL)
mainScmGit.init(env.BRANCH_NAME)
notify = new Notifier(env, steps, currentBuild,
pipelineLibraryScmGit, mainScmGit, 'Jenkinsfile',
)
defaultNodeLabel = env.DEFAULT_NODE ?: 'master || !master'
// eg github-zanata-org/zanata-platform/update-Jenkinsfile
jobName = env.JOB_NAME
Expand Down Expand Up @@ -188,7 +199,7 @@ timestamps {
checkout scm

// Clean the workspace
sh "git clean -dfqx"
sh "git clean -fdx"
}

// Build and Unit Tests
Expand Down Expand Up @@ -217,7 +228,7 @@ timestamps {
clean install jxr:aggregate \
--batch-mode \
--update-snapshots \
-DstaticAnalysisCI \
-DstaticAnalysis \
$gwtOpts \
-DskipFuncTests \
-DskipArqTests \
Expand All @@ -234,7 +245,7 @@ timestamps {
// TODO try https://github.com/jenkinsci/github-pr-coverage-status-plugin

// send test coverage data to codecov.io
codecov(env, steps, PROJ_URL)
codecov(env, steps, mainScmGit)

// notify if compile+unit test successful
// TODO update notify (in pipeline library) to support Rocket.Chat webhook integration
Expand Down Expand Up @@ -274,6 +285,7 @@ timestamps {
//step([$class: 'PmdPublisher', pattern: '**/target/pmd.xml', unstableTotalAll:'0'])
//step([$class: 'DryPublisher', canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '**/cpd/cpdCheck.xml', unHealthy: ''])

// TODO reduce unstableTotal thresholds as bugs are eliminated
step([$class: 'FindBugsPublisher',
pattern: '**/findbugsXml.xml',
unstableTotalAll: '0'])
Expand All @@ -288,7 +300,7 @@ timestamps {
//[parserName: 'appserver log messages'], // 119 warnings
//[parserName: 'browser warnings'], // 0 warnings
],
unstableTotalAll: '0',
unstableTotalAll: '300',
unstableTotalHigh: '0',
])
// TODO check integration test warnings (EAP and WildFly)
Expand All @@ -311,7 +323,7 @@ timestamps {
includes: '**/target/**, **/src/main/resources/**,**/.zanata-cache/**'
}
// Reduce workspace size
sh "git clean -dfqx"
sh "git clean -fdx"
} catch (e) {
echo("Caught exception: " + e)
notify.error(e.toString())
Expand Down Expand Up @@ -378,7 +390,7 @@ void integrationTests(String appserver) {
dir(appserver) {
checkout scm
// Clean the workspace
sh "git clean -dfqx"
sh "git clean -fdx"

unstash 'generated-files'

Expand Down Expand Up @@ -466,7 +478,7 @@ void integrationTests(String appserver) {
testDataPublishers: [[$class: 'StabilityTestDataPublisher']]
)
// Reduce workspace size
sh "git clean -dfqx"
sh "git clean -fdx"
} else {
notify.error("No integration test result for $appserver")
currentBuild.result = 'FAILURE'
Expand Down Expand Up @@ -497,10 +509,9 @@ void withPorts(Closure wrapped) {
// from https://issues.jenkins-ci.org/browse/JENKINS-27395?focusedCommentId=256459&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-256459
boolean setJUnitPrefix(prefix, files) {
// add prefix to qualified classname
def fileGlob = "**/${files}"
def reportFiles = findFiles glob: fileGlob
def reportFiles = findFiles glob: "**/${files}"
if (reportFiles.size() > 0) {
sh "set +x; echo 'Using sed to edit classnames in ${fileGlob}'; sed -i \"s/\\(<testcase .*classname=['\\\"]\\)\\([a-z]\\)/\\1${prefix.toUpperCase()}.\\2/g\" ${reportFiles.join(" ")}"
sh "sed -i \"s/\\(<testcase .*classname=['\\\"]\\)\\([a-z]\\)/\\1${prefix.toUpperCase()}.\\2/g\" ${reportFiles.join(" ")}"
return true
} else {
echo "[WARNING] Failed to find JUnit report files **/${files}"
Expand Down
18 changes: 16 additions & 2 deletions build-tools/src/test/java/TestJenkinsfile.java
Expand Up @@ -17,6 +17,7 @@
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource;
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library;
import static java.lang.Boolean.TRUE;
import static org.assertj.core.api.Assertions.assertThat;

// try 'extends BasePipelineTest' for debugging in case of weird Groovy exceptions
public class TestJenkinsfile extends BasePipelineTestCPS {
Expand Down Expand Up @@ -131,9 +132,12 @@ protected Object doCall(T args) {
return "JBOSS_HTTP_PORT=51081\nSMTP_PORT=34765\n";
}
if (script.startsWith("git ls-remote")) {
// ScmGit.getPullRequestNum in zanata-pipeline-library uses this:
// ScmGit.init in zanata-pipeline-library uses these:
if (script.endsWith("refs/pull/*/head")) {
return "1234567890123456789012345678901234567890 refs/pull/123/head";
} else if (script.endsWith("refs/heads/*")) {
return "fc2b7c527e4401c03bcaf2833739d16e77698ab6 refs/heads/master\n" +
"b0d3e2ff4696f2702f4b4fbac3b59b6cf9a76790 refs/heads/ZNTA-2234-tag" ;
} else {
// Notifier.groovy in zanata-pipeline-library uses this:
return "1234567890123456789012345678901234567890 abcdef\n";
Expand All @@ -154,7 +158,17 @@ public void shouldExecuteWithoutErrors() throws Exception {
runScript("../Jenkinsfile");
printCallStack();
assertJobStatusSuccess();
// TODO add assertions about call stack (but not too fragile)

boolean verified = getHelper().getCallStack()
.stream()
.filter(it -> it.getMethodName().equals("sh") && it.argsToString().contains("mvn"))
// snoop on mvn commands in the stream
// .peek(it -> System.out.printf("%s\n\n", it.argsToString()))
.anyMatch(it -> {
String args = it.argsToString();
return args.contains("-Dappserver=") && args.contains("install");
});
assertThat(verified).isTrue();
} catch (CpsCallableInvocation e) {
// if the script fails, we need the call stack to tell us where the problem is
// (CpsCallableInvocation tells us very little)
Expand Down

0 comments on commit 01ac9eb

Please sign in to comment.