Skip to content

Commit

Permalink
feat(3059): Add pipeline level customization for pipeline template (#560
Browse files Browse the repository at this point in the history
)
  • Loading branch information
klu909 committed Mar 14, 2024
1 parent aeb930e commit 045816d
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 17 deletions.
10 changes: 5 additions & 5 deletions config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const SCHEMA_CONFIG_PRE_TEMPLATE_MERGE = Joi.object()
.keys({
template: Joi.string().regex(Regex.FULL_TEMPLATE_NAME_WITH_NAMESPACE),
version: Joi.number().integer().min(1).max(50),
annotations: Annotations.annotations.when('template', { is: Joi.exist(), then: Joi.forbidden() }),
annotations: Annotations.annotations,
jobs: SCHEMA_JOBS.when('template', { is: Joi.exist(), then: Joi.forbidden(), otherwise: Joi.required() }),
shared: Joi.when('template', {
is: Joi.exist(),
Expand All @@ -78,11 +78,11 @@ const SCHEMA_CONFIG_PRE_TEMPLATE_MERGE = Joi.object()
}),
otherwise: SCHEMA_SHARED
}),
cache: SCHEMA_CACHE.when('template', { is: Joi.exist(), then: Joi.forbidden() }),
childPipelines: SCHEMA_CHILD_PIPELINES.when('template', { is: Joi.exist(), then: Joi.forbidden() }),
cache: SCHEMA_CACHE,
childPipelines: SCHEMA_CHILD_PIPELINES,
stages: SCHEMA_STAGES.when('template', { is: Joi.exist(), then: Joi.forbidden() }),
subscribe: SCHEMA_SUBSCRIBE.when('template', { is: Joi.exist(), then: Joi.forbidden() }),
parameters: Parameters.parameters.default({}).when('template', { is: Joi.exist(), then: Joi.forbidden() })
subscribe: SCHEMA_SUBSCRIBE,
parameters: Parameters.parameters.default({})
})
.unknown(false);

Expand Down
13 changes: 8 additions & 5 deletions config/pipelineTemplate.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
'use strict';

const Joi = require('joi');
const JobsSchema = require('./base').jobs;
const Shared = require('./base').shared;
const BaseSchema = require('./base');
const Annotations = require('./annotations');
const Parameters = require('./parameters');
const Template = require('./template');
const Regex = require('./regex');

const SCHEMA_CONFIG = Joi.object()
.keys({
jobs: JobsSchema.required(),
shared: Shared,
parameters: Parameters.parameters.default({})
jobs: BaseSchema.jobs.required(),
shared: BaseSchema.shared,
parameters: Parameters.parameters.default({}),
annotations: Annotations.annotations,
cache: BaseSchema.cache,
subscribe: BaseSchema.subscribe
})
.unknown(false);

Expand Down
30 changes: 25 additions & 5 deletions test/data/config.base.pipelineTemplate.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
template: foo/bar@1.0.0
shared:
image: node:20
environment:
FOO: user overwrite
settings:
email: foo@example.com
image: node:20
environment:
FOO: user overwrite
settings:
email: foo@example.com
cache:
pipeline: ["node_modules/", "~/.sbt"]
event: ["target/generated-intermediate-resouce/*"]
job:
build: ["target/some-artifact.zip"]
publish-preview: ["target/some-artifact.zip"]
test: []
subscribe:
scmUrls:
- git@github.com:foo/bar.git#master: [~commit, ~tags, ~release]
annotations:
foo: a
bar: b
parameters:
color: [red, blue]
childPipelines:
scmUrls:
- git@github.com:org/repo.git
- https://github.com:org/repo2.git
startAll: true
66 changes: 64 additions & 2 deletions test/data/config.pipelineTemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,69 @@ maintainer: foo@bar.com
config:
jobs:
main:
requires:
- ~commit
- ~pr
- ~subscribe
steps:
- init: npm install
- test: npm test
- hello: echo hello
shared:
image: node:20
environment:
FOO: user overwrite
settings:
email: foo@example.com
blockedBy: [~main]
cache: true
description: 'This is a description!'
annotations:
foo: a
bar: b
freezeWindows:
- "* * ? * 1"
- "0-59 0-23 * 1 ?"
matrix:
NODE_VERSION:
- 18
- 20
parameters:
color: [red, blue]
provider:
name: aws
region: us-west-2
accountId: 111111111111
role: arn:aws:iam::111111111111:role/role
executor: eks
clusterName: sd-build-eks
requires: ~commit
secrets:
- NPM_TOKEN
sourcePaths:
- src/A
- src/AConfig
template: foo/bar@1.0.0
order:
- install
- test
- other
- echo
steps:
- install: npm install
- test: npm test
- echo: echo $FOO
cache:
pipeline: ["node_modules/", "~/.sbt"]
event: ["target/generated-intermediate-resouce/*"]
job:
build: ["target/some-artifact.zip"]
publish-preview: ["target/some-artifact.zip"]
test: []
subscribe:
scmUrls:
- git@github.com:foo/bar.git#master: [~commit, ~tags, ~release]
annotations:
foo: a
bar: b
parameters:
color: [red, blue]

0 comments on commit 045816d

Please sign in to comment.