From d3c2f4cbfb181fbe35899a9b79ef802c20e3c1d9 Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Sun, 7 Jun 2020 18:35:36 +0200 Subject: [PATCH 1/3] #1 Add configurable base url for API testing and provide Maven profile for DukeCon testing instance --- pom.xml | 16 ++++++++++++++++ src/test/java/org/dukecon/WebResourcesTests.java | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1cc51b5..d015735 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,8 @@ UTF-8 11 11 + + https://latest.dukecon.org/javaland/2019 @@ -52,6 +54,11 @@ maven-surefire-plugin 2.22.1 + + + ${dukecon.apitests.baseurl} + + maven-jar-plugin @@ -77,4 +84,13 @@ + + + + testing + + https://testing.dukecon.org/javaland/2019 + + + diff --git a/src/test/java/org/dukecon/WebResourcesTests.java b/src/test/java/org/dukecon/WebResourcesTests.java index b4ca8ea..43d096f 100644 --- a/src/test/java/org/dukecon/WebResourcesTests.java +++ b/src/test/java/org/dukecon/WebResourcesTests.java @@ -13,9 +13,14 @@ public class WebResourcesTests { + private static String baseUrl + = System.getProperty("dukecon.apitests.baseurl", + "https://latest.dukecon.org/javaland/2019"); + @BeforeEach public void setup() { - RestAssured.baseURI = "https://latest.dukecon.org/javaland/2019"; + System.out.println ("Testing '" + baseUrl + "'"); + RestAssured.baseURI = baseUrl; RestAssured.port = 443; RestAssured.registerParser("text/css", Parser.TEXT); } From 9ac5061896311889f462efc214b5ea98aafee309 Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Sun, 7 Jun 2020 20:27:27 +0200 Subject: [PATCH 2/3] #2 Add Jenkinsfile to execute Maven based build + test --- Jenkinsfile | 38 ++++++++++++++++++++++++++++++++++++++ pom.xml | 4 ++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..763f934 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,38 @@ +#!/usr/bin/env groovy +@Library('jenkins-library@master') _ + +pipeline { + agent { + node { + label 'docker' + } + } + + options { + disableConcurrentBuilds() + buildDiscarder(logRotator(numToKeepStr: '5', daysToKeepStr: '5')) + } + + triggers { + pollSCM('*/3 * * * *') + } + + stages { + stage('API Test') { + steps { + sh "mvn clean test" + } + } + } + post { + always { + sendNotification currentBuild.result + } + failure { + // notify users when the Pipeline fails + mail to: 'gerd@aschemann.net', + subject: "Failed DukeCon API Test Pipeline: ${currentBuild.fullDisplayName}", + body: "Something is wrong with ${env.BUILD_URL}" + } + } +} diff --git a/pom.xml b/pom.xml index d015735..970febe 100644 --- a/pom.xml +++ b/pom.xml @@ -13,8 +13,8 @@ UTF-8 - 11 - 11 + 8 + 8 https://latest.dukecon.org/javaland/2019 From dd48273d6ee4df33cd851c0e6c1cc00ce956e36d Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Mon, 8 Jun 2020 07:41:30 +0200 Subject: [PATCH 3/3] #2 Enable choice of test target (profile) in Jenkinsfile --- Jenkinsfile | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 763f934..71172dd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,6 +13,14 @@ pipeline { buildDiscarder(logRotator(numToKeepStr: '5', daysToKeepStr: '5')) } + parameters { + choice( + name: "testTarget", + choices: "latest\ntesting", + description: "Set the DukeCon target environment for testing" + ) + } + triggers { pollSCM('*/3 * * * *') } @@ -20,7 +28,7 @@ pipeline { stages { stage('API Test') { steps { - sh "mvn clean test" + sh "mvn ${mvnProfile(params.testTarget)} clean test" } } } @@ -36,3 +44,10 @@ pipeline { } } } + +def mvnProfile(testTarget) { + if ("latest" != testTarget) { + return "-P ${testTarget}" + } + return "" +} \ No newline at end of file