This commit is contained in:
2020-04-18 19:00:27 +02:00
parent 168fc577d9
commit dde41c085e
14 changed files with 156 additions and 67 deletions

View File

@ -0,0 +1,102 @@
/* eslint-disable max-len */
const general = { jenkinsfile: '' };
const node = { jenkinsfile: '', js: '' };
general.jenkinsfile = `pipeline {
agent any
environment {
VERSION = VersionNumber([
versionNumberString:
'\${BUILDS_ALL_TIME}',
versionPrefix: '1.0.',
worstResultForIncrement: 'SUCCESS'
])
publish = 0
}
stages {
stage('Setup') {
steps {
script {
currentBuild.displayName = env.VERSION
}
echo 'Setting up test environment'
sh 'echo setup'
}
}
}
post {
success {
script {
publish = sh script: "git log -1 | grep '\\\\[no publish\\\\]'", returnStatus: true
if (publish != 0) {
echo 'Deploying'
sh 'echo deploy'
} else {
echo 'Build successful, Commit not marked for deploying'
currentBuild.result = "UNSTABLE"
}
}
}
}
}
`;
node.jenkinsfile = `pipeline {
agent any
environment {
VERSION = VersionNumber([
versionNumberString:
'\${BUILDS_ALL_TIME}',
versionPrefix: '1.0.',
worstResultForIncrement: 'SUCCESS'
])
}
stages {
stage('Building') {
steps {
script {
currentBuild.displayName = env.VERSION
}
sh 'yarn ci \${VERSION}'
}
}
}
}
`;
node.js = `/* eslint-disable no-process-exit */
/* eslint-disable no-console */
/* eslint-disable no-sync */
'use strict';
const fs = require ('fs');
const child_process = require ('child_process');
const pkg = JSON.parse (fs.readFileSync ('package.json', 'utf-8'));
[
,, pkg.version
] = process.argv;
fs.writeFileSync ('package.json', JSON.stringify (pkg, null, 2));
child_process.execSync ('yarn lint', { stdio: 'inherit' });
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.test === 'string')
child_process.execSync ('yarn test', { stdio: 'inherit' });
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.compile === 'string')
child_process.execSync ('yarn compile', { stdio: 'inherit' });
child_process.exec ('git log -1 | grep \\'\\\\[no publish\\\\]\\'')
.addListener ('exit', (code) => {
if (code === 0) {
console.log ('build not marked for deployment');
process.exit (1);
}
else { child_process.execSync ('yarn publish'); }
});
`;
export { general, node };

View File

@ -9,11 +9,9 @@ import { Confirm } from 'enquirer';
import { Snippet } from '../../Snippet';
import { apply_template, modify_json } from '../../Helper';
import node_js from './template/node/jenkins.js.asset';
import node_jenkinsfile from './template/node/Jenkinsfile.asset';
import general_jenkinsfile from './template/general/Jenkinsfile.asset';
import { general, node } from './Assets';
export class Jenkins implements Snippet {
export default class Jenkins implements Snippet {
public async start (): Promise<void> {
const is_node = await new Confirm ({
message: 'is the current project using nodejs?',
@ -22,8 +20,8 @@ export class Jenkins implements Snippet {
.run ();
if (is_node) {
await apply_template (node_js, 'jenkins.js');
await apply_template (node_jenkinsfile, 'Jenkinsfile');
await apply_template (node.js, 'jenkins.js');
await apply_template (node.jenkinsfile, 'Jenkinsfile');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await modify_json ((obj: any): any => {
obj.scripts.ci = 'yarn && node jenkins.js';
@ -31,7 +29,7 @@ export class Jenkins implements Snippet {
});
}
else {
await apply_template (general_jenkinsfile, 'Jenkinsfile');
await apply_template (general.jenkinsfile, 'Jenkinsfile');
}
}
}

View File

@ -1,39 +0,0 @@
pipeline {
agent any
environment {
VERSION = VersionNumber([
versionNumberString:
'${BUILDS_ALL_TIME}',
versionPrefix: '1.0.',
worstResultForIncrement: 'SUCCESS'
])
publish = 0
}
stages {
stage('Setup') {
steps {
script {
currentBuild.displayName = env.VERSION
}
echo 'Setting up test environment'
sh 'echo setup'
}
}
}
post {
success {
script {
publish = sh script: "git log -1 | grep '\\[no publish\\]'", returnStatus: true
if (publish != 0) {
echo 'Deploying'
sh 'echo deploy'
} else {
echo 'Build successful, Commit not marked for deploying'
currentBuild.result = "UNSTABLE"
}
}
}
}
}

View File

@ -1,23 +0,0 @@
pipeline {
agent any
environment {
VERSION = VersionNumber([
versionNumberString:
'${BUILDS_ALL_TIME}',
versionPrefix: '1.0.',
worstResultForIncrement: 'SUCCESS'
])
}
stages {
stage('Building') {
steps {
script {
currentBuild.displayName = env.VERSION
}
sh 'yarn ci ${VERSION}'
}
}
}
}

View File

@ -1,28 +0,0 @@
/* eslint-disable no-process-exit */
/* eslint-disable no-console */
/* eslint-disable no-sync */
'use strict';
const fs = require ('fs');
const child_process = require ('child_process');
const pkg = JSON.parse (fs.readFileSync ('package.json', 'utf-8'));
[
,, pkg.version
] = process.argv;
fs.writeFileSync ('package.json', JSON.stringify (pkg, null, 2));
child_process.execSync ('yarn lint', { stdio: 'inherit' });
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.test === 'string')
child_process.execSync ('yarn test', { stdio: 'inherit' });
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.compile === 'string')
child_process.execSync ('yarn compile', { stdio: 'inherit' });
child_process.exec ('git log -1 | grep \'\\[no publish\\]\'')
.addListener ('exit', (code) => {
if (code === 0) {
console.log ('build not marked for deployment');
process.exit (1);
}
else { child_process.execSync ('yarn publish'); }
});