Skip to content

Instantly share code, notes, and snippets.

@garunski
Last active September 7, 2018 07:25
Show Gist options
  • Save garunski/29c2d2e941529d519812e895b4f70958 to your computer and use it in GitHub Desktop.
Save garunski/29c2d2e941529d519812e895b4f70958 to your computer and use it in GitHub Desktop.
#!/usr/bin/groovy
timestamps {
podTemplate(
label: 'jenkins-pipeline',
inheritFrom: 'default',
containers: [
containerTemplate(name: 'docker', image: 'docker:18.06', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'helm', image: 'lachlanevenson/k8s-helm:v2.10.0', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'chrome', image: 'garunski/alpine-chrome:latest', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'selenium', image: 'selenium/standalone-chrome:3.14', command: '', ttyEnabled: false, ports: [portMapping(containerPort: 4444)]),
]
) {
node ('jenkins-pipeline') {
stage('Get latest version of code') {
checkout scm
}
container ('chrome') {
stage('Install Packages') {
sh 'npm install --quiet'
}
stage('Code Formatting checks') {
sh 'npm run lint'
}
stage('Build') {
sh 'npm run build'
}
stage('Run Unit Tests') {
sh 'npm run test-ci'
junit 'test-results/**/*.xml'
}
} //end container chrome
stage('Run Code Coverage') {
cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/cobertura.xml', conditionalCoverageTargets: '70, 0, 0', failUnhealthy: false, failUnstable: false, lineCoverageTargets: '80, 0, 0', maxNumberOfBuilds: 0, methodCoverageTargets: '80, 0, 0', onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false
}
stage('Deploy Local') {
println 'Building docker image'
container('docker') {
sh "echo \$'FROM nginx:stable-alpine \nCOPY ./dist /usr/share/nginx/html \n' > Dockerfile"
sh 'docker build -t jobrm:latest .'
}
println 'Deploying The website to the local cluster'
container('helm') {
sh 'helm upgrade --install --force jobrm-static ./charts/jobrm-static --set image.repository=jobrm --set image.tag=latest --set service.type=NodePort --set service.nodePort=31001'
}
} //end deploy local
stage('Run Integration Tests') {
container ('chrome') {
sh 'npm run e2e-ci'
}
junit 'e2e/test-results/**/*.xml'
}
stage('Deploy Production') {
}
stage('Run Post Deployment Tests') {
}
} // end node
} // end podTemplate
} // end timestamps
const { SpecReporter } = require('jasmine-spec-reporter');
const { JUnitXmlReporter } = require('jasmine-reporters');
exports.config = {
allScriptsTimeout: 11000,
specs: ['./e2e/**/*.e2e-spec.ts'],
capabilities: {
browserName: 'chrome'
},
directConnect: false,
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
const specReporter = new SpecReporter({
spec: { displayStacktrace: true }
});
jasmine.getEnv().addReporter(specReporter);
const junitReporter = new JUnitXmlReporter({
savePath: './e2e/test-results/E2E',
consolidateAll: false
});
jasmine.getEnv().addReporter(junitReporter);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment