Skip to content

Commit af17ddb

Browse files
authored
fix(3106): Allow user to customize job when using pipeline template (#567)
1 parent 0530a47 commit af17ddb

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

config/base.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,26 @@ const SCHEMA_SUBSCRIBE = Joi.object().keys({
6363
)
6464
});
6565

66+
const ALLOWED_JOB_FIELDS_WITH_PIPELINE_TEMPLATE = Joi.object().keys({
67+
image: Job.image,
68+
environment: Job.environment,
69+
settings: Job.settings,
70+
requires: Job.requires
71+
});
72+
6673
const SCHEMA_CONFIG_PRE_TEMPLATE_MERGE = Joi.object()
6774
.keys({
6875
template: Joi.string().regex(Regex.FULL_TEMPLATE_NAME_WITH_NAMESPACE),
6976
version: Joi.number().integer().min(1).max(50),
7077
annotations: Annotations.annotations,
71-
jobs: SCHEMA_JOBS.when('template', { is: Joi.exist(), then: Joi.forbidden(), otherwise: Joi.required() }),
78+
jobs: Joi.when('template', {
79+
is: Joi.exist(),
80+
then: Joi.object().pattern(Job.jobName, ALLOWED_JOB_FIELDS_WITH_PIPELINE_TEMPLATE).unknown(false),
81+
otherwise: SCHEMA_JOBS.required()
82+
}),
7283
shared: Joi.when('template', {
7384
is: Joi.exist(),
74-
then: Joi.object().keys({
75-
image: Job.image,
76-
environment: Job.environment,
77-
settings: Job.settings,
78-
requires: Job.requires
79-
}),
85+
then: ALLOWED_JOB_FIELDS_WITH_PIPELINE_TEMPLATE,
8086
otherwise: SCHEMA_SHARED
8187
}),
8288
cache: SCHEMA_CACHE,

test/data/config.base.pipelineTemplate-customized.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ shared:
66
settings:
77
email: foo@example.com
88
requires: ~commit
9+
10+
jobs:
11+
main:
12+
requires: [~commit]
13+
image: node:20
14+
settings:
15+
email: [test@email.com, test3@email.com]
16+
environment:
17+
VAR3: "three"
18+
VAR1: "empty"

0 commit comments

Comments
 (0)