diff --git a/email-notif/Jenkinsfile b/email-notif/Jenkinsfile new file mode 100644 index 0000000..445d916 --- /dev/null +++ b/email-notif/Jenkinsfile @@ -0,0 +1,36 @@ +node { + + // config + def to = emailextrecipients([ + [$class: 'CulpritsRecipientProvider'], + [$class: 'DevelopersRecipientProvider'], + [$class: 'RequesterRecipientProvider'] + ]) + + try { + stage('Build') { + println('Build stage passed...') + } + stage('Test') { + println('Test stage failed') + sh 'exit 1' + } + } catch(e) { + // Label build + currentBuild.result = "FAILURE"; + + // Email variables + def subject = "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} ${currentBuild.result}" + def content = '${JELLY_SCRIPT,template="html"}' + + // Send email notification + if(to != null && !to.isEmpty()) { + emailext(body: content, mimeType: 'text/html', + replyTo: '$DEFAULT_REPLYTO', subject: subject, + to: to, attachLog: true ) + } + + // mark current build as a failure and throw the error + throw e; + } +} \ No newline at end of file diff --git a/job-dsl/createpipeline.groovy b/job-dsl/createpipeline.groovy new file mode 100644 index 0000000..bb95e05 --- /dev/null +++ b/job-dsl/createpipeline.groovy @@ -0,0 +1,18 @@ +// job('DSL - Create Pipeline Job') { +// scm { +// git('https://github.com/bohemian-coder/nodeJS-jenkins-docker.git') { node -> // is hudson.plugins.git.GitSCM +// node / gitConfigName('bohemian-coder') +// node / gitConfigEmail('jenniferejeme@gmail.com') +// branches('jenkins-pipeline') +// } +// } +// scriptPath('../Jenkinsfile') +// triggers { +// scm('H/5 * * * *') +// } +// wrappers { +// nodejs('nodejs') +// } +// steps { +// } +// } \ No newline at end of file diff --git a/job-dsl/nodedocker.groovy b/job-dsl/nodedocker.groovy new file mode 100644 index 0000000..73b3837 --- /dev/null +++ b/job-dsl/nodedocker.groovy @@ -0,0 +1,26 @@ +job('NodeJS Docker Jenkins - DSL') { + scm { + git('https://github.com/bohemian-coder/nodeJS-jenkins-docker.git') { node -> // is hudson.plugins.git.GitSCM + node / gitConfigName('bohemian-coder') + node / gitConfigEmail('jenniferejeme@gmail.com') + branches('jenkins-dsl') + } + } + triggers { + scm('H/5 * * * *') + } + wrappers { + nodejs('nodejs') + } + steps { + dockerBuildAndPublish { + repositoryName('maybellemo/node-jenkins-docker') + tag('${GIT_REVISION,length=9}') + registryCredentials('dockercredentials') + forcePull(false) + forceTag(false) + createFingerprints(false) + skipDecorate() + } + } +} \ No newline at end of file diff --git a/job-dsl/nodejs.groovy b/job-dsl/nodejs.groovy new file mode 100644 index 0000000..9c6d49e --- /dev/null +++ b/job-dsl/nodejs.groovy @@ -0,0 +1,17 @@ +job('NodeJS app') { + scm { + git('https://github.com/bohemian-coder/nodeJS-jenkins-docker.git') { node -> // is hudson.plugins.git.GitSCM + node / gitConfigName('bohemian-coder') + node / gitConfigEmail('jenniferejeme@gmail.com') + } + } + triggers { + scm('H/5 * * * *') + } + wrappers { + nodejs('nodejs') + } + steps { + shell("npm install") + } +} \ No newline at end of file diff --git a/job-pipeline/Jenkinsfile.v1 b/job-pipeline/Jenkinsfile.v1 new file mode 100644 index 0000000..ff1ff4a --- /dev/null +++ b/job-pipeline/Jenkinsfile.v1 @@ -0,0 +1,21 @@ +node +{ + def git_commit_id + + stage('Preparation') { + checkout scm + sh "git rev-parse --short HEAD > .git/commit-id" + git_comit_id = readFile('.git/commit-id').trim() + } + stage('Tesmting') { + nodejs(nodeJSInstallationName: 'nodejs') { + sh 'npm install' + sh 'npm test' + } + } + stage('Docker build and push') { + docker.withRegistry('https://index.docker.io/v2/', 'dockercredentials') { + def app = docker.build("maybellemo/node-jenkins-docker:${git_commit_id}", '.').push() + } + } +} \ No newline at end of file diff --git a/job-pipeline/Jenkinsfile.v2 b/job-pipeline/Jenkinsfile.v2 new file mode 100644 index 0000000..ef4733b --- /dev/null +++ b/job-pipeline/Jenkinsfile.v2 @@ -0,0 +1,31 @@ +node { + def git_comit_id + stage('Preparation') { + checkout scm + sh "git rev-parse --short HEAD > .git/commit-id" + git_comit_id = readFile('.git/commit-id').trim() + } + stage('test') { + def dbTestContainer = docker.image('node:16') + dbTestContainer.pull() + dbTestContainer.inside { + sh 'npm install' + sh 'npm test' + } + } + stage('test with database') { + def mysql = docker.image('mysql').run("-e MYSQL_ALLOW_EMPTY_PASSWORD=yes") + def dbTestContainer = docker.image('node:16') + dbTestContainer.pull() + dbTestContainer.inside("--link ${mysql.id}:mysql") { //host: mysql, port: 3306 + sh 'npm install' + sh 'npm test' + } + mysql.stop() + } + stage('docker build/push') { + docker.withRegistry('https://index.docker.io/v2/', 'dockercredentials') { + def app = docker.build("maybellemo/node-jenkins-docker:${git_comit_id }", '.').push() + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 6021c89..3e9fc49 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,10 @@ "express": "^4.18.2", "http-errors": "^2.0.0", "inherits": "^2.0.4", - "mocha": "^10.2.0", - "mysql2": "^3.3.3" + "mysql2": "^3.3.3", + "mocha": "^10.2.0" + }, + "devDependencies": { + } } diff --git a/test/test.js b/test/test.js index 9592531..4ffbb66 100644 --- a/test/test.js +++ b/test/test.js @@ -6,3 +6,4 @@ describe('Array', function() { }); }); }); +/* For demo purposes: This test will always succeed*/ \ No newline at end of file