Skip to content

Commit 29d5506

Browse files
authored
[com.circleci.v2] Support specifying custom job-level parameters while calling a job in a workflow (#86)
So far there was no way to specify these custom parameters while calling a workflow job. This allows user to specify custom `parameters` while invoking a WorkflowJob.
1 parent 0b01a8d commit 29d5506

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

packages/com.circleci.v2/Config.pkl

+11
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ class WorkflowJob {
366366

367367
/// Job Filters can have the key branches or tags
368368
filters: JobFilters?
369+
370+
/// Supplemental job-level parameters to be specified when
371+
/// [calling a `job` in `workflow`](https://circleci.com/docs/configuration-reference/#jobs-in-workflow).
372+
///
373+
/// There are several reserved parameter names that cannot be used from CircleCI users.
374+
hidden parameters: Mapping<
375+
String(!(this is "name"|"context"|"filters"|"matrix"|"requires"|"type")),
376+
*Listing<Step>|String|Number|Boolean
377+
>?
369378
}
370379

371380
class JobFilters {
@@ -786,6 +795,8 @@ output {
786795
if (it.hasProperty("__name__"))
787796
Map(it.__name__, it.toMap().remove("__name__"))
788797
else it
798+
[WorkflowJob] = (it) ->
799+
it.toMap() + (it.parameters ?? Map()).toMap()
789800
}
790801
}
791802
}

packages/com.circleci.v2/PklProject

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
amends "../basePklProject.pkl"
1818

1919
package {
20-
version = "1.2.0"
20+
version = "1.3.0"
2121
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//===----------------------------------------------------------------------===//
2+
// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//===----------------------------------------------------------------------===//
16+
amends ".../Config.pkl"
17+
// Adaptation of https://github.com/CircleCI-Public/aws-ecr-orb/blob/v9.3.7/src/examples/build_and_push_image_w_registry_login.yml#L21-L36
18+
19+
version = "2.1"
20+
21+
orbs {
22+
["aws-ecr"] = "circleci/aws-ecr@9.0"
23+
["aws-cli"] = "circleci/aws-cli@5.1"
24+
}
25+
26+
workflows {
27+
["build-and-push-image-with-container-registry-login"] {
28+
jobs {
29+
new {
30+
["aws-ecr/build_and_push_image"] {
31+
parameters {
32+
["container_registry_login"] = true
33+
["registry_login"] {
34+
module.run("docker login -u ${HEROKU_USERNAME} -p ${HEROKU_API_KEY}")
35+
module.run("docker login -u ${GITHUB_USERNAME} -p ${GITHUB_TOKEN}")
36+
module.run("docker login -u ${DOCKERHUB_ID} -p ${DOCKERHUB_PASSWORD}")
37+
}
38+
["auth"] {
39+
(module.OrbStep("aws-cli/setup")) {
40+
role_arn = "arn:aws:iam::123456789012"
41+
}
42+
}
43+
["repo"] = "my-sample-repo"
44+
["tag"] = "sampleTag"
45+
["dockerfile"] = "Dockerfile"
46+
["path"] = "."
47+
["region"] = "us-west-2"
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}

packages/com.circleci.v2/tests/Config.pkl-expected.pcf

+30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
examples {
2+
["build_and_push_image_w_registry_login.yaml"] {
3+
"""
4+
# Generated from CircleCI.pkl. DO NOT EDIT.
5+
version: '2.1'
6+
orbs:
7+
aws-ecr: circleci/aws-ecr@9.0
8+
aws-cli: circleci/aws-cli@5.1
9+
workflows:
10+
build-and-push-image-with-container-registry-login:
11+
jobs:
12+
- aws-ecr/build_and_push_image:
13+
container_registry_login: true
14+
registry_login:
15+
- run:
16+
command: docker login -u ${HEROKU_USERNAME} -p ${HEROKU_API_KEY}
17+
- run:
18+
command: docker login -u ${GITHUB_USERNAME} -p ${GITHUB_TOKEN}
19+
- run:
20+
command: docker login -u ${DOCKERHUB_ID} -p ${DOCKERHUB_PASSWORD}
21+
auth:
22+
- aws-cli/setup:
23+
role_arn: arn:aws:iam::123456789012
24+
repo: my-sample-repo
25+
tag: sampleTag
26+
dockerfile: Dockerfile
27+
path: '.'
28+
region: us-west-2
29+
30+
"""
31+
}
232
["concurrent_workflow.yaml"] {
333
"""
434
# Generated from CircleCI.pkl. DO NOT EDIT.

0 commit comments

Comments
 (0)