diff --git a/config/regex.js b/config/regex.js index 21a35bdc..cb6cbc44 100644 --- a/config/regex.js +++ b/config/regex.js @@ -41,7 +41,8 @@ module.exports = { // Steps can only be named with A-Z,a-z,0-9,-,_ STEP_NAME: /^[\w-]+$/, // Jobs can only be named with A-Z,a-z,0-9,-,_ - JOB_NAME: /^[\w-]+$/, + // Also allow stage setup/teardown like stage@stage-name:setup + JOB_NAME: /^(([\w-]+)|(?:stage@([\w-]+):(setup|teardown)))$/, // PR JOB Name can only be PR-1 or PR-1:main, group1: PR-prNum, group2: jobName PR_JOB_NAME: /^(PR-\d+)(?::([\w-]+))?$/, // Match all possible job name diff --git a/models/job.js b/models/job.js index 02c80fc1..0f130b16 100644 --- a/models/job.js +++ b/models/job.js @@ -9,7 +9,7 @@ const MODEL = { id: Joi.number().integer().positive().description('Identifier of this Job').example(123345), name: Joi.string() - .regex(/^(PR-[0-9]+:)?[\w-]+$/) + .regex(/^(PR-[0-9]+:)?(([\w-]+)|(?:stage@([\w-]+):(setup|teardown)))$/) .max(110) .description('Name of the Job') .example('main'), diff --git a/test/config/regex.test.js b/test/config/regex.test.js index fa87abaf..b0edecab 100644 --- a/test/config/regex.test.js +++ b/test/config/regex.test.js @@ -261,10 +261,15 @@ describe('config regex', () => { describe('jobs', () => { it('checks good job names', () => { assert.isTrue(config.regex.JOB_NAME.test('foo-BAR_15')); + assert.isTrue(config.regex.JOB_NAME.test('stage@integration:setup')); + assert.isTrue(config.regex.JOB_NAME.test('stage@production-blue:teardown')); }); it('fails on bad job names', () => { assert.isFalse(config.regex.JOB_NAME.test('run all the things')); + assert.isFalse(config.regex.JOB_NAME.test('stage@integration')); + assert.isFalse(config.regex.JOB_NAME.test('stage@integration:deploy')); + assert.isFalse(config.regex.JOB_NAME.test('integration:deploy')); }); it('checks good PR job names', () => {