Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const RESERVED_PIPELINE_ANNOTATIONS = [
'screwdriver.cd/pipelineDescription',
'screwdriver.cd/useDeployKey'
];
const RESERVED_STAGE_ANNOTATIONS = ['screwdriver.cd/manualStartEnabled'];

/**
* The definition of the annotations pieces
Expand All @@ -48,5 +49,6 @@ const RESERVED_PIPELINE_ANNOTATIONS = [
module.exports = {
annotations: SCHEMA_ANNOTATIONS,
reservedJobAnnotations: RESERVED_JOB_ANNOTATIONS,
reservedPipelineAnnotations: RESERVED_PIPELINE_ANNOTATIONS
reservedPipelineAnnotations: RESERVED_PIPELINE_ANNOTATIONS,
reservedStageAnnotations: RESERVED_STAGE_ANNOTATIONS
};
3 changes: 2 additions & 1 deletion config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const SCHEMA_STAGE = Joi.object()
setup: SCHEMA_SETUP_JOB,
teardown: SCHEMA_TEARDOWN_JOB,
requires: Job.requires,
sourcePaths: Job.sourcePaths
sourcePaths: Job.sourcePaths,
annotations: Annotations.annotations
})
.unknown(false);

Expand Down
21 changes: 21 additions & 0 deletions migrations/20260901000000-add-annotations-columns-to-stages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable new-cap */

'use strict';

const prefix = process.env.DATASTORE_SEQUELIZE_PREFIX || '';
const table = `${prefix}stages`;

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.sequelize.transaction(async transaction => {
await queryInterface.addColumn(
table,
'annotations',
{
type: Sequelize.TEXT
},
{ transaction }
);
});
}
};
15 changes: 11 additions & 4 deletions models/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const Joi = require('joi');
const Regex = require('../config/regex');
const Annotations = require('../config/annotations');
const mutate = require('../lib/mutate');

const MODEL = {
Expand All @@ -22,6 +23,8 @@ const MODEL = {

description: Joi.string().max(256).description('Description of the Stage').example('Deploys canary jobs'),

annotations: Annotations.annotations.description('Stage-level annotations'),

archived: Joi.boolean().description('Flag if the stage is archived').example(true).default(false)
};

Expand Down Expand Up @@ -49,7 +52,11 @@ module.exports = {
* @type {Joi}
*/
get: Joi.object(
mutate(MODEL, ['id', 'pipelineId', 'name', 'jobIds'], ['description', 'setup', 'teardown', 'archived'])
mutate(
MODEL,
['id', 'pipelineId', 'name', 'jobIds'],
['description', 'setup', 'teardown', 'annotations', 'archived']
)
).label('Get Stage metadata'),

/**
Expand All @@ -58,9 +65,9 @@ module.exports = {
* @property update
* @type {Joi}
*/
update: Joi.object(mutate(MODEL, [], ['jobIds', 'description', 'setup', 'teardown', 'archived'])).label(
'Update Stage'
),
update: Joi.object(
mutate(MODEL, [], ['jobIds', 'description', 'setup', 'teardown', 'annotations', 'archived'])
).label('Update Stage'),

/**
* List of fields that determine a unique row
Expand Down
3 changes: 3 additions & 0 deletions test/data/config.base.stages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ canary:
description: "Canary jobs for testing"
sourcePaths:
- src/
annotations:
scrwedriver.cd/manualStartEnabled: false
foo: bar
prod:
jobs:
- deploy-west
Expand Down
4 changes: 4 additions & 0 deletions test/data/stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ jobIds: [1, 2, 3, 4]
description: 'Deploys canary jobs'
setup: 222
teardown: 333
annotations:
screwdriver.cd/manualStartEnabled: true
screwdriver.cd/foo: bar
baz: qux