Skip to content

Commit

Permalink
Add optional build parameter to build with saucelabs instead (#1952)
Browse files Browse the repository at this point in the history
* Add optional build parameter to build with saucelabs instead
* nobody is using the code-cov html reports, so stop them for now
* use array of jenkins versions so its not copy and pasted
  • Loading branch information
halkeye authored Apr 17, 2019
1 parent 3404024 commit e3e4ddc
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 78 deletions.
1 change: 1 addition & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ RUN apt-get update -qqy \
build-essential \
python \
iputils-ping \
net-tools \
locales \
libsass-dev \
&& rm -rf /var/lib/apt/lists/* \
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM debian
RUN apt update && \
apt install -y wget && \
rm -rf /var/lib/apt/lists/* && \
wget -O - https://saucelabs.com/downloads/sc-4.5.3-linux.tar.gz | tar xvzf -
ENV BUILD_TAG ""
RUN printf "#!/bin/bash \n\
if [ -z \"\$BUILD_TAG\" ]; then\n\
/sc-4.5.3-linux/bin/sc -u \$SAUCE_USERNAME -k \$SAUCE_ACCESS_KEY \n\
else\n\
/sc-4.5.3-linux/bin/sc -u \$SAUCE_USERNAME -k \$SAUCE_ACCESS_KEY -i \$BUILD_TAG \n\
fi \n\
\n" > /entrypoint.sh && chmod 755 /entrypoint.sh
ENTRYPOINT /entrypoint.sh
171 changes: 99 additions & 72 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,94 +8,121 @@ if (JENKINS_URL == 'https://ci.jenkins.io/') {
return
}

// only 20 builds
properties([buildDiscarder(logRotator(artifactNumToKeepStr: '20', numToKeepStr: '20'))])
properties([
// only 20 builds,
buildDiscarder(logRotator(artifactNumToKeepStr: '20', numToKeepStr: '20')),
parameters([
booleanParam(name: 'USE_SAUCELABS', defaultValue: false)
])
])

node() {
stage('Setup') {
deleteDir()
checkout scm
sh 'docker build -t blueocean_build_env --build-arg GID=$(id -g ${USER}) --build-arg UID=$(id -u ${USER}) - < Dockerfile.build'
withCredentials([file(credentialsId: 'blueoceandeploy_ath', variable: 'FILE')]) {
sh 'mv $FILE acceptance-tests/live.properties'
}
configFileProvider([configFile(fileId: 'blueocean-maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mv $MAVEN_SETTINGS settings.xml'
}
withCredentials([file(credentialsId: 'blueocean-ath-private-repo-key', variable: 'FILE')]) {
sh 'mv $FILE acceptance-tests/bo-ath.key'
}
sh "./acceptance-tests/runner/scripts/start-selenium.sh"
sh "./acceptance-tests/runner/scripts/start-bitbucket-server.sh"
}
credentials = [
file(credentialsId: 'blueoceandeploy_ath', variable: 'LIVE_PROPERTIES_FILE'),
file(credentialsId: 'blueocean-ath-private-repo-key', variable: 'BO_ATH_KEY_FILE')
]

try {
docker.image('blueocean_build_env').inside("--net=container:blueo-selenium") {
withEnv(['[email protected]','GIT_COMMITTER_NAME=Hates','GIT_AUTHOR_NAME=Cake','[email protected]']) {
stage('Sanity check dependencies') {
sh "node ./bin/checkdeps.js"
sh "node ./bin/checkshrinkwrap.js"
}
envs = [
'[email protected]',
'GIT_COMMITTER_NAME=Hates',
'GIT_AUTHOR_NAME=Cake',
'[email protected]'
]

stage('Building JS Libraries') {
sh 'node -v && npm -v'
sh 'npm --prefix ./js-extensions run build'
}
jenkinsVersions = ['2.138.4']

stage('Building BlueOcean') {
timeout(time: 90, unit: 'MINUTES') {
sh "mvn clean install -V -B -DcleanNode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Dmaven.test.failure.ignore -s settings.xml -Dmaven.artifact.threads=30"
}
if (params.USE_SAUCELABS) {
credentials.add(usernamePassword(credentialsId: 'saucelabs', passwordVariable: 'SAUCE_ACCESS_KEY', usernameVariable: 'SAUCE_USERNAME'))
withCredentials([usernamePassword(credentialsId: 'saucelabs', passwordVariable: 'SAUCE_ACCESS_KEY', usernameVariable: 'SAUCE_USERNAME')]) {
envs.add("webDriverUrl=https://${env.SAUCE_USERNAME}:${env.SAUCE_ACCESS_KEY}@ondemand.saucelabs.com/wd/hub")
}
envs.add("saucelabs=true")
envs.add("TUNNEL_IDENTIFIER=${env.BUILD_TAG}")
}

if (env.JOB_NAME =~ 'blueocean-weekly-ath') {
jenkinsVersions.add('2.121.1')
jenkinsVersions.add('2.150.3')
}

node() {
withCredentials(credentials) {
withEnv(envs) {

junit '**/target/surefire-reports/TEST-*.xml'
junit '**/target/jest-reports/*.xml'
jacoco execPattern: '**/target/jacoco.exec', classPattern : '**/target/classes', sourcePattern: '**/src/main/java', exclusionPattern: 'src/test*'
archive '*/target/code-coverage/**/*'
archive '*/target/*.hpi'
archive '*/target/jest-coverage/**/*'
stage('Setup') {
deleteDir()
checkout scm
sh 'docker build -t blueocean_build_env --build-arg GID=$(id -g ${USER}) --build-arg UID=$(id -u ${USER}) - < Dockerfile.build'
sh 'mv $LIVE_PROPERTIES_FILE acceptance-tests/live.properties'
configFileProvider([configFile(fileId: 'blueocean-maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mv $MAVEN_SETTINGS settings.xml'
}
sh 'mv $BO_ATH_KEY_FILE acceptance-tests/bo-ath.key'
if (params.USE_SAUCELABS) {
sh "./acceptance-tests/runner/scripts/start-sc.sh"
} else {
sh "./acceptance-tests/runner/scripts/start-selenium.sh"
}
sh "./acceptance-tests/runner/scripts/start-bitbucket-server.sh"
}

stage('ATH - Jenkins 2.138.4') {
timeout(time: 90, unit: 'MINUTES') {
sh "cd acceptance-tests && bash -x ./run.sh -v=2.138.4 --no-selenium --settings='-s ${env.WORKSPACE}/settings.xml'"
junit 'acceptance-tests/target/surefire-reports/*.xml'
archive 'acceptance-tests/target/screenshots/**/*'
try {
docker.image('blueocean_build_env').inside("--net=container:blueo-selenium") {
ip = sh(returnStdout: true, script: "hostname -I | awk '{print \$1}'").trim()
echo "IP: [${ip}]"
stage('Sanity check dependencies') {
sh "node ./bin/checkdeps.js"
sh "node ./bin/checkshrinkwrap.js"
}
}

if (env.JOB_NAME =~ 'blueocean-weekly-ath') {
stage('ATH - Jenkins 2.73.2') {
sh "cd acceptance-tests && bash -x ./run.sh -v=2.73.2 --no-selenium --settings='-s ${env.WORKSPACE}/settings.xml'"
junit 'acceptance-tests/target/surefire-reports/*.xml'
stage('Building JS Libraries') {
sh 'node -v && npm -v'
sh 'npm --prefix ./js-extensions run build'
}
stage('ATH - Jenkins 2.73.3') {
sh "cd acceptance-tests && bash -x ./run.sh -v=2.73.3 --no-selenium --settings='-s ${env.WORKSPACE}/settings.xml'"
junit 'acceptance-tests/target/surefire-reports/*.xml'

stage('Building BlueOcean') {
timeout(time: 90, unit: 'MINUTES') {
sh "mvn clean install -V -B -DcleanNode -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Dmaven.test.failure.ignore -s settings.xml -Dmaven.artifact.threads=30"
}

junit '**/target/surefire-reports/TEST-*.xml'
junit '**/target/jest-reports/*.xml'
jacoco execPattern: '**/target/jacoco.exec', classPattern : '**/target/classes', sourcePattern: '**/src/main/java', exclusionPattern: 'src/test*'
// archive '*/target/code-coverage/**/*'
archive '*/target/*.hpi'
// archive '*/target/jest-coverage/**/*'
}
stage('ATH - Jenkins 2.107.2') {
sh "cd acceptance-tests && bash -x ./run.sh -v=2.107.2 --no-selenium --settings='-s ${env.WORKSPACE}/settings.xml'"
junit 'acceptance-tests/target/surefire-reports/*.xml'

jenkinsVersions.each { version ->
stage("ATH - Jenkins ${version}") {
timeout(time: 90, unit: 'MINUTES') {
dir('acceptance-tests') {
sh "bash -x ./run.sh -v=${version} --host=${ip} --no-selenium --settings='-s ${env.WORKSPACE}/settings.xml'"
junit '**/target/surefire-reports/*.xml'
archive '**/target/screenshots/**/*'
}
}
}
}
stage('ATH - Jenkins 2.121.1') {
sh "cd acceptance-tests && bash -x ./run.sh -v=2.121.1 --no-selenium --settings='-s ${env.WORKSPACE}/settings.xml'"
junit 'acceptance-tests/target/surefire-reports/*.xml'
}
} catch(err) {
echo(err)
currentBuild.result = "FAILURE"

if (err.toString().contains('exit code 143')) {
currentBuild.result = "ABORTED"
}
} finally {
stage('Cleanup') {
if (params.USE_SAUCELABS) {
sh "${env.WORKSPACE}/acceptance-tests/runner/scripts/stop-sc.sh"
} else {
sh "${env.WORKSPACE}/acceptance-tests/runner/scripts/stop-selenium.sh"
}
sh "${env.WORKSPACE}/acceptance-tests/runner/scripts/stop-bitbucket-server.sh"
deleteDir()
}
}
}

} catch(err) {
currentBuild.result = "FAILURE"

if (err.toString().contains('exit code 143')) {
currentBuild.result = "ABORTED"
}
} finally {
stage('Cleanup') {
sh "${env.WORKSPACE}/acceptance-tests/runner/scripts/stop-selenium.sh"
sh "${env.WORKSPACE}/acceptance-tests/runner/scripts/stop-bitbucket-server.sh"
deleteDir()
}
}
}

29 changes: 25 additions & 4 deletions acceptance-tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,31 @@ if [ -z "$JENKINS_WAR" ]; then
export JENKINS_WAR=../bin/jenkins-${JENKINS_VERSION}.war
fi

if [ "${RUN_SELENIUM}" == "true" ]; then
./runner/scripts/start-selenium.sh
./runner/scripts/start-bitbucket-server.sh
fi
function finish() {
if [ "${RUN_SELENIUM}" == "true" ]; then
if [ "${SAUCE_ACCESS_KEY}" == "true" ]; then
./runner/scripts/stop-sc.sh
else
./runner/scripts/stop-selenium.sh
fi
./runner/scripts/stop-bitbucket-server.sh
fi
}

function start() {
if [ "${RUN_SELENIUM}" == "true" ]; then
if [ "${SAUCE_ACCESS_KEY}" == "true" ]; then
./runner/scripts/start-sc.sh
else
./runner/scripts/start-selenium.sh
fi
./runner/scripts/start-bitbucket-server.sh
fi
}

trap finish EXIT
start


while true; do
curl -v http://localhost:7990 2>&1 | grep 'Location: http://localhost:7990/dashboard' > /dev/null
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/runner/scripts/start-bitbucket-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $SCRIPT_DIR/stop-bitbucket-server.sh
echo ""
echo " Starting Bitbucket Docker container..."
echo ""
docker run --net=container:blueo-selenium -e BITBUCKET_HOME=/var/atlassian --name="blueo-bitbucket" -d hadashi/bitbucket-server
docker run --net=host -e BITBUCKET_HOME=/var/atlassian --name="blueo-bitbucket" -d hadashi/bitbucket-server
#docker run --name blueo-bitbucket -d -t -p 7990:7990 hadashi/blueocean-bitbucket-server atlas-run-standalone -u 6.3.0 --product bitbucket --version 5.2.0 --data-version 5.2.0 --jvmargs -Xmx4096M -DskipAllPrompts
#SELENIUM_IP=`docker inspect -f '{{ .NetworkSettings.IPAddress }}' blueo-selenium`
#mkdir -p ./target
Expand Down
17 changes: 17 additions & 0 deletions acceptance-tests/runner/scripts/start-sc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

SCRIPT_DIR=$(dirname $0)
$SCRIPT_DIR/stop-sc.sh

echo ""
echo " Starting Sauce Connect container..."
echo ""
docker run \
-d \
--name blueo-selenium \
--net host \
-e SAUCE_ACCESS_KEY \
-e SAUCE_USERNAME \
-e BUILD_TAG \
--rm \
blueocean/sauceconnect:4.5.3
6 changes: 5 additions & 1 deletion acceptance-tests/runner/scripts/start-selenium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ $SCRIPT_DIR/stop-selenium.sh
echo ""
echo " Starting Selenium Docker container..."
echo ""
docker run -d --name blueo-selenium -p 15900:5900 -p 7990:7990 -p 7999:7999 -p 4444:4444 -e no_proxy=localhost selenium/standalone-chrome-debug:3.141.59 > /dev/null
docker run -d --name blueo-selenium \
--net=host \
-e no_proxy=localhost \
-v /dev/shm:/dev/shm \
selenium/standalone-chrome-debug:3.141.5

# Output the containers bridge network IP to file
SELENIUM_IP=`docker inspect -f '{{ .NetworkSettings.IPAddress }}' blueo-selenium`
Expand Down
8 changes: 8 additions & 0 deletions acceptance-tests/runner/scripts/stop-sc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

echo ""
echo " Stopping old Sauce Connect container, if any. This may take a few seconds..."
docker stop blueo-selenium > /dev/null
docker rm blueo-selenium > /dev/null
echo " ... stopped"
echo ""
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.blueocean.ath;

import com.google.common.base.Strings;
import com.google.inject.AbstractModule;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.name.Names;
Expand Down Expand Up @@ -78,6 +79,9 @@ protected void configure() {
}
capability.setCapability("extendedDebugging", "true");
capability.setCapability("initialBrowserUrl", launchUrl);
if (!Strings.isNullOrEmpty(cfg.getString("TUNNEL_IDENTIFIER"))) {
capability.setCapability("tunnelIdentifier", cfg.getString("TUNNEL_IDENTIFIER"));
}

WebDriver driver = new RemoteWebDriver(new URL(webDriverUrl), capability);
LocalDriver.setCurrent(driver);
Expand Down

0 comments on commit e3e4ddc

Please sign in to comment.