Skip to content
Permalink
Browse files
More ATH shenanigans + a Jenkinsfile (#44)
* Added a simple Jenkinsfile

* Use docker-selenium images

* Use official images in the local start selenium scripts

* More tweaking of the Jenkinsfile

* And more tweaking of the Jenkinsfile again

* what's the pwd

* what's the pwd

* what's the pwd

* Map in a volume for ~/.m2

* Map in a volume for ~/.m2

* No clue what I'm doing

* revert BS tests

* please show me something

* dir doesn't work as you'd expect, it seems

* come on

* come on

* come on

* come on

* come on

* come on

* come on

* come on

* come on

* Ok ... needed plugins update and also see JENKINS-33510 .... ffs

* Trying to get it to build ... rest-impl tests hanging

* Changes to blueocean-ath-firefox

* Changes to blueocean-ath-builder

* Build BO and ATH on the executor

* Try get it working on executor

* Try get it working on executor

* Nope .... must build inside a docker container so as to get node etc

* Try and expose a port range

* Back to not building in a container

* Run the ATH

* Back to not running selenium

* printip

* printip

* printip

* printip

* printip

* printip

* printip

* printip

* Allow control of the http port used by the ATH Jenkins instance

* Can I see variables inside the docker image ...

* Allow spec of the blueocean host

* Start selenium in the Jenkinsfile and try connecting

* temp move build outside docker build container

* More jiggery pokery

* More jiggery pokery

* More jiggery pokery

* More jiggery pokery

* removed dead comment

* omg

* Fixed build of bo

* maven repo

* maven repo - more

* maven repo - more

* maven repo - more

* maven repo - more

* maven repo - more

* use a local nexus repo

* use a local nexus repo

* use a local nexus repo

* use a local nexus repo

* use a local nexus repo

* use a local nexus repo

* use a local nexus repo

* use a local nexus repo

* use a local nexus repo

* use a local nexus repo

* local repo binding

* local repo binding

* getting closer

the secret .... run on linux

* print out the env

* What is setting the env grrr

* Fix  jenkins_url file

* bind the port for the jenskins server

* Switch off selenium on the run script

* Switch off selenium on the run script

* Better messages on the start stop scripts

* Updated the local docker file

* Remove local .m2 binding

* Build the docker image for building

* See if it will work without an image name

* Nope ... didn't work

* Add docker label on node

* use mvn tool

* Can't run that node scrpit on a slave that already has an old node

* export the selenium server container IP address

* Connect using the docker bridge network

* sudo source

* Can't execute the script as source ... write IP to file

* Trim process.env.BLUEO_SELENIUM_SERVER_ADDR

* Try it on the CI Server

* Cleaned up messages from selenium-docker start scripts

* Use maven exit code for run script exit

* removed echo of exception as it was causing an NPE

* Trying to get the classic Jenkins pages working better

* Make the target dir if not already there

* Make moveClassicBottomStickyButtons complete more deterministic

* Fix moveClassicBottomStickyButtons to complete if used on a non-classic Jenkins page

* Remove the page head completely for classic Jenkins pages

* Fix activity page object "Open" toast selector

* Logging

* Cleanup move sticky buttons complete

* More cleanup of classic Jenkins page_object tweaks

* Get an env

* try checkout of branch by the same name

* try checkout of branch by the same name

* try checkout of branch by the same name

* try checkout of branch by the same name

* try checkout of branch by the same name

* try checkout of branch by the same name

* try checkout of branch by the same name

* try checkout of branch by the same name

* try checkout of branch by the same name

* try checkout of branch by the same name

* parameterise the branch name

* parameterise the branch name - some comments in the Jenkinsfile

* Output a message if we find a branch by that name

* Fix comment in Jenkinsfile
  • Loading branch information
tfennelly committed Sep 26, 2016
1 parent a5c04bb commit 6aac5c09b5614833cb2bcd78bc346a7e4dd0c2da
Show file tree
Hide file tree
Showing 24 changed files with 549 additions and 97 deletions.
@@ -0,0 +1,2 @@
var netaddr = require('network-address');
console.log(netaddr());
@@ -1,7 +1,61 @@
FROM cloudbees/java-build-tools
FROM ubuntu:16.04

ENV MAVEN_VERSION 3.3.3
ENV NODE_VERSION 6.4.0

USER root

RUN apt-get update
RUN apt-get install -y libxml2-utils libssl-dev

# ENTRYPOINT bash
#========================
# Miscellaneous packages
#========================
RUN apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
sudo \
openjdk-8-jdk \
tar \
zip xz-utils \
curl wget \
git \
build-essential \
python \
iputils-ping \
&& rm -rf /var/lib/apt/lists/* \
&& sed -i 's/securerandom\.source=file:\/dev\/random/securerandom\.source=file:\/dev\/urandom/' ./usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/java.security

#==========
# Maven
#==========
RUN curl -fsSL http://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz | tar xzf - -C /usr/share \
&& mv /usr/share/apache-maven-$MAVEN_VERSION /usr/share/maven \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME /usr/share/maven


#===============
# Node and NPM
#===============
RUN wget --no-verbose https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz -O /opt/nodejs.tar.xz
RUN tar -C /usr/local --strip-components 1 -xJf /opt/nodejs.tar.xz
RUN mkdir /.npm && chmod 777 /.npm

#=============================================
# Misc packages needed by the ATH
#=============================================
RUN apt-get update -qqy \
&& apt-get -qqy --no-install-recommends install \
libxml2-utils \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

#========================================
# Add normal user with passwordless sudo
#========================================
RUN sudo useradd bouser --shell /bin/bash --create-home \
&& sudo usermod -a -G sudo bouser \
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \
&& echo 'bouser:secret' | chpasswd

USER bouser
WORKDIR /home/bouser
@@ -0,0 +1,70 @@
#!groovy

node ('docker') {

// Allow the pipeline to be built with parameters, defaulting the
// Blue Ocean branch name to be that of the ATH branch name. If no such branch
// of Blue Ocean exists, then the ATH will just run against the master branch of
// Blue Ocean.
properties([parameters([string(defaultValue: "${env.BRANCH_NAME}", description: 'Blue Ocean branch name against which the tests on this ATH branch will run', name: 'BLUEOCEAN_BRANCH_NAME')]), pipelineTriggers([])])

stage 'init'
//deleteDir()
checkout scm

// Run selenium in a docker container of its own on the host.
// It will output the selenium server address to ./target/.selenium_ip
sh "./start-selenium.sh"
def seleniumIP = readFile './target/.selenium_ip'

try {
// Build an image from the the local Dockerfile
def athImg = docker.build('blueocean-ath-builder')

// Expose the port on which the ATH Jenkins instance runs (12345), allowing the
// Firefox browser (running in the selenium container) to make requests back
// in etc.
//
// To bind in the local ~/.m2 when running in dev mode, simply add the following
// volume binding to the "inside" container run settings (change username from "tfennelly"):
// -v /home/tfennelly/.m2:/home/bouser/.m2
//
athImg.inside("--expose=12345 -p 12345:12345") {
withEnv(["BLUEO_SELENIUM_SERVER_ADDR=${seleniumIP}"]) {
try {
sh "echo 'Starting build stage'"
// Build blueocean and the ATH
stage 'build'
dir('blueocean-plugin') {
// Try checking out the Blue Ocean branch having the name supplied by build parameter. If that fails
// (i.e. doesn't exist ), just use the default/master branch and run the ATH tests against that.
try {
git (url: 'https://github.com/jenkinsci/blueocean-plugin.git', branch: "${BLUEOCEAN_BRANCH_NAME}")
echo "Found a Blue Ocean branch named '${BLUEOCEAN_BRANCH_NAME}'. Running ATH against that branch."
} catch (Exception e) {
echo "No Blue Ocean branch named '${BLUEOCEAN_BRANCH_NAME}'. Running ATH against 'master' instead."
}
// Need test-compile because the rest-impl has a test-jar that we
// need to make sure gets compiled and installed for other modules.
// Must cd into blueocean-plugin before running build
// see https://issues.jenkins-ci.org/browse/JENKINS-33510
sh "cd blueocean-plugin && mvn -B clean test-compile install -DskipTests"
}
sh "mvn -B clean install -DskipTests"

// Run the ATH. Tell the run script to not try starting selenium. Selenium is
// already running in a docker container of it's on in the host. See call to
// ./start-selenium.sh (above) and ./stop-selenium.sh (below).
stage 'run'
sh "./run.sh -a=./blueocean-plugin/blueocean/ --host=\"`node .printip.js`\" --port=12345 --no-selenium"
} catch (err) {
currentBuild.result = "FAILURE"
} finally {
//deleteDir()
}
}
}
} finally {
sh "./stop-selenium.sh"
}
}
@@ -1,7 +1,10 @@
module.exports = (function (settings) {
var fs = require('fs');
var url = require('url');
var launchUrl;

var netaddr = require('network-address');

if (process.env.LAUNCH_URL) {
//
// This allows you to run the tests against a Jenkins instance of
@@ -28,9 +31,31 @@ module.exports = (function (settings) {
launchUrl = fs.readFileSync(jenkins_url_file, 'utf8');
}

console.log('Jenkins running at: ' + launchUrl);

// Replace localhost addresses with the actual IP, allowing it
// to work inside a docker container running on the host.
launchUrl = launchUrl.replace('localhost', netaddr());
launchUrl = launchUrl.replace('127.0.0.1', netaddr());

var launchUrlObj = url.parse(launchUrl);

settings.test_settings.default.launch_url = launchUrl;
settings.test_settings.default.selenium_host = launchUrlObj.hostname;

if (process.env.BLUEO_SELENIUM_SERVER_ADDR) {
settings.test_settings.default.selenium_host = process.env.BLUEO_SELENIUM_SERVER_ADDR.trim();
}

console.log('Jenkins running at: ' + settings.test_settings.default.launch_url);
console.log(" NOTE:");
console.log(" Selenium and the browser (Firefox) are running in a docker");
console.log(" container that also has VNC. This allows you to connect if");
console.log(" you'd like to look at the browser while the tests run.");
console.log(" Simple run:");
console.log(" $ open vnc://:secret@localhost:15900");
console.log("");
console.log(" NOTE:");
console.log(" The selenium server is at " + settings.test_settings.default.selenium_host + ":4444");
console.log("");

if (fs.existsSync('target/.selenium_server_provided')) {
settings.selenium.start_process = false;
@@ -25,23 +25,22 @@
"devDependencies": {
"@jenkins-cd/js-modules": "0.0.8",
"@jenkins-cd/sse-gateway": "0.0.9",
"async": "^2.0.1",
"events": "1.1.1",
"eventsource": "0.2.1",
"faker": "^3.1.0",
"fs-extra": "^0.30.0",
"glob": "^7.0.6",
"gulp": "^3.9.1",
"gulp-jsdoc3": "^0.3.0",
"gulp-shell": "^0.5.2",
"gulp-watch": "^4.3.9",
"network-address": "^1.1.0",
"nightwatch": "0.9.8",
"nodegit": "^0.14.1",
"phantomjs-prebuilt": "2.1.12",
"request": "2.74.0",
"util": "0.10.3",
"xmlhttprequest": "1.8.0"
},
"dependencies": {
"async": "^2.0.1",
"faker": "^3.1.0"
}
}
42 run.sh
@@ -24,7 +24,11 @@
JENKINS_VERSION=2.7.3
SELENIUM_VERSION=2.53

MAVEN_SETTINGS=""
LOCAL_SNAPSHOTS=false
RUN_SELENIUM=true
ATH_SERVER_HOST=""
ATH_SERVER_PORT=""
PLUGINS=""
AGGREGATOR_DIR=""
AGGREGATOR_ENV=""
@@ -45,6 +49,18 @@ case $i in
-s|--snaps|--snapshots)
LOCAL_SNAPSHOTS=true
;;
--no-selenium)
RUN_SELENIUM=false
;;
--settings=*)
MAVEN_SETTINGS="${i#*=}"
;;
-h=*|--host=*)
ATH_SERVER_HOST="${i#*=}"
;;
-p=*|--port=*)
ATH_SERVER_PORT="${i#*=}"
;;
-d|--dev)
DEV_JENKINS=true
;;
@@ -144,7 +160,17 @@ if [ "${AGGREGATOR_DIR}" != "" ]; then
AGGREGATOR_ENV="PLUGINS_DIR=${AGGREGATOR_DIR}/target/plugins"
fi

EXECUTION="env JENKINS_JAVA_OPTS=${JENKINS_JAVA_OPTS} BROWSER=phantomjs LOCAL_SNAPSHOTS=${LOCAL_SNAPSHOTS} ${PLUGINS} ${AGGREGATOR_ENV} PATH=./node:./node/npm/bin:./node_modules/.bin:${PATH} JENKINS_WAR=./bin/jenkins-${JENKINS_VERSION}.war mvn test ${PROFILES} ${TEST_TO_RUN}"
if [ "${MAVEN_SETTINGS}" != "" ]; then
MAVEN_SETTINGS="-s ${MAVEN_SETTINGS}"
fi
if [ "${ATH_SERVER_HOST}" != "" ]; then
ATH_SERVER_HOST="blueoceanHost=${ATH_SERVER_HOST}"
fi
if [ "${ATH_SERVER_PORT}" != "" ]; then
ATH_SERVER_PORT="httpPort=${ATH_SERVER_PORT}"
fi

EXECUTION="env JENKINS_JAVA_OPTS=\"${JENKINS_JAVA_OPTS}\" ${ATH_SERVER_HOST} ${ATH_SERVER_PORT} BROWSER=phantomjs LOCAL_SNAPSHOTS=${LOCAL_SNAPSHOTS} ${PLUGINS} ${AGGREGATOR_ENV} PATH=./node:./node/npm/bin:./node_modules/.bin:${PATH} JENKINS_WAR=./bin/jenkins-${JENKINS_VERSION}.war mvn ${MAVEN_SETTINGS} test ${PROFILES} ${TEST_TO_RUN}"

echo ""
echo "> ${EXECUTION}"
@@ -154,10 +180,20 @@ echo "------------------------------------------------"

# Download the jenkins war
source download.sh "http://mirrors.jenkins-ci.org/war-stable/${JENKINS_VERSION}/jenkins.war" "bin/jenkins-${JENKINS_VERSION}.war"
# Download Selenium standalone
source download.sh "http://selenium-release.storage.googleapis.com/${SELENIUM_VERSION}/selenium-server-standalone-${SELENIUM_VERSION}.0.jar" "bin/selenium-server-standalone-${SELENIUM_VERSION}.1.jar"

if [ "${RUN_SELENIUM}" == "true" ]; then
./start-selenium.sh
fi

# Run the tests
EXIT_CODE=0
eval "${EXECUTION}"
if [ $? != 0 ];then
EXIT_CODE=1
fi

if [ "${RUN_SELENIUM}" == "true" ]; then
./stop-selenium.sh
fi

exit $EXIT_CODE
@@ -37,9 +37,22 @@ public abstract class BOJUnitTest extends AbstractJUnitTest {
@Before
public void doInit() throws IOException {
FileWriter fileWriter = new FileWriter("./target/.jenkins_url");
fileWriter.write(jenkins.getCurrentUrl());
fileWriter.write(getJenkinsUrl());
fileWriter.flush();
fileWriter.close();
new FileWriter("./target/.jenkins_test").close();
}

protected String getJenkinsUrl() {
String jenkinsUrl = jenkins.getCurrentUrl();
String host = System.getenv("blueoceanHost");

if (host != null) {
host = host.trim();
jenkinsUrl = jenkinsUrl.replace("127.0.0.1", host);
jenkinsUrl = jenkinsUrl.replace("localhost", host);
}

return jenkinsUrl;
}
}

0 comments on commit 6aac5c0

Please sign in to comment.