1.1.8 • Published 3 years ago

circleci-cdk v1.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

circleci-cdk

Config Development Kit for CircleCI. Write your pipelines in TypeScript instead of struggling with the documentation and YAML.

Installation

npm

npm install circleci-cdk --save-dev

yarn

yarn add circleci-cdk -D

Examples

Hello world pipeline

const pipeline = Pipeline.create((pipeline) => {
  pipeline.addWorkflow('my-workflow', (workflow) => {
    workflow.addJobConfig('hello-world')
  })

  pipeline.addJob('hello-world', (job) => {
    job.addDocker('cimg/node:14.17')
    job.addStep(Steps.run(`echo "Hello World"`))
  })
})
console.log(pipeline.toConfigString())

The code above will print:

version: 2.1
workflows:
  my-workflow:
    jobs:
      - hello-world
jobs:
  hello-world:
    docker:
      - cimg/node:14.17
    steps:
      - echo "Hello World"

Add configuration

const pipeline = Pipeline.create((pipeline) => {
  pipeline.addWorkflow('my-workflow', (workflow) => {
    workflow.addJobConfig('hello-world', (jobConfig) => {
      jobConfig.contexts = ['my-context']
    })
  })

  pipeline.addJob('hello-world', (job) => {
    job.addDocker('cimg/node:14.17')

    job.addStep(
      Steps.run(`echo "Hello World"`, (step) => {
        step.workingDirectory = '/my-project'
      }),
    )
  })
})
console.log(pipeline.toConfigString())

will generate

version: 2.1
workflows:
  my-workflow:
    jobs:
      - hello-world:
          context:
            - my-context
jobs:
  hello-world:
    docker:
      - cimg/node:14.17
    steps:
      - command: echo "Hello World"
        working_directory: /my-project

Using variables

const pipeline = Pipeline.create((pipeline) => {
  pipeline.addWorkflow('my-workflow', (workflow) => {
    workflow.addJobConfig('hello-world')
  })

  pipeline.addJob('hello-world', (job) => {
    job.addDocker('cimg/node:14.17')

    job.addStep(
      Steps.custom('my-command', {
        name: 'Joe',
      }),
    )
  })

  pipeline.addCommand('my-command', (command) => {
    command.addParameter('name', Parameters.string())
    command.addStep(
      Steps.run(
        variables`echo "hello ${({ parameters }) =>
          parameters.name} in pipeline ${({ pipeline }) => pipeline.id}"`,
      ),
    )
  })
})
console.log(pipeline.toConfigString())

will generate

version: 2.1
workflows:
  my-workflow:
    jobs:
      - hello-world
jobs:
  hello-world:
    docker:
      - cimg/node:14.17
    steps:
      - my-command:
          name: Joe
commands:
  my-command:
    steps:
      - echo "hello << parameters.name >> in pipeline << pipeline.id >>"
    parameters:
      name: string
1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.5

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago