Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit d6f56ba

Browse files
authored
docs(sample): add orb example project (#179)
1 parent b37a7b2 commit d6f56ba

File tree

7 files changed

+2514
-0
lines changed

7 files changed

+2514
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 2.1
2+
orbs:
3+
continuation: circleci/[email protected]
4+
node: circleci/[email protected]
5+
setup: true
6+
jobs:
7+
generate-config:
8+
executor: node/default
9+
steps:
10+
- checkout
11+
- node/install-packages:
12+
app-dir: .circleci/src
13+
- run:
14+
name: Generate config
15+
command: cd .circleci/src && npm run generate
16+
- continuation/continue:
17+
configuration_path: /home/circleci/project/.circleci/src/dynamicConfig.yml
18+
workflows:
19+
dynamic-workflow:
20+
jobs:
21+
- generate-config
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as CircleCI from "@circleci/circleci-config-sdk";
2+
3+
const nodeExecutor = new CircleCI.executors.DockerExecutor(
4+
`cimg/node:19.8.1`,
5+
"small"
6+
);
7+
8+
export { nodeExecutor }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as CircleCI from '@circleci/circleci-config-sdk';
2+
import { SlackOrb } from './orbs';
3+
import { nodeExecutor } from './executors';
4+
5+
const myConfig = new CircleCI.Config();
6+
const myWorkflow = new CircleCI.Workflow('my-workflow');
7+
myConfig.importOrb(SlackOrb);
8+
9+
const myJob = new CircleCI.Job('example-job', nodeExecutor, [
10+
new CircleCI.commands.Checkout(),
11+
new CircleCI.commands.Run({ command: 'npm install' }),
12+
new CircleCI.commands.Run({ command: 'npm test' }),
13+
new CircleCI.reusable.ReusedCommand(SlackOrb.commands['notify'], {
14+
event: "pass",
15+
template: "basic_success_1",
16+
} )
17+
]);
18+
19+
myConfig.addJob(myJob);
20+
myWorkflow.addJob(myJob);
21+
22+
myConfig.addWorkflow(myWorkflow);
23+
myConfig.writeFile('dynamicConfig.yml')
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as CircleCI from "@circleci/circleci-config-sdk";
2+
// Though reusable config in CircleCI can be replaced with JavaScript in many cases, often we want to take advantage of
3+
// the existing Orbs that are already provided by the community and CircleCI team.
4+
5+
// We will be using the Slack orb
6+
// https://circleci.com/developer/orbs/orb/circleci/slack
7+
8+
// The Slack orb's included command and job happen to share the same parameters.
9+
const SlackParams = new CircleCI.parameters.CustomParametersList([
10+
new CircleCI.parameters.CustomParameter("branch_pattern", "string"),
11+
new CircleCI.parameters.CustomParameter("tag_pattern", "string"),
12+
new CircleCI.parameters.CustomParameter("channel", "string"),
13+
new CircleCI.parameters.CustomEnumParameter("event", ["fail", "pass", "always"]),
14+
new CircleCI.parameters.CustomParameter("mentions", "string"),
15+
new CircleCI.parameters.CustomParameter("custom", "string"),
16+
new CircleCI.parameters.CustomParameter("template", "string"),
17+
])
18+
19+
// The manifest gives us access to the components provided by the orb and their parameters in TypeScript, with proper type checking.
20+
const SlackOrbManifest: CircleCI.types.orb.OrbImportManifest = {
21+
commands: {
22+
notify: SlackParams,
23+
},
24+
jobs: {
25+
"on-hold": SlackParams,
26+
},
27+
executors: {},
28+
};
29+
30+
// Export the "imported" orb, which we can then use in our config.
31+
export const SlackOrb = new CircleCI.orb.OrbImport(
32+
"slack", // The "alias" of the orb, used to reference it in the config
33+
"circleci", // The namespace of the orb
34+
"slack", // The name of the orb
35+
"4.12", // The version of the orb
36+
"An optional description of the orb",
37+
SlackOrbManifest // The manifest gives us access to the commands and jobs provided by the orb in TypeScript
38+
);

0 commit comments

Comments
 (0)