Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
circleci-cli: circleci/circleci-cli@0.1.9
Use circleci-cli
elements in your existing workflows and jobs.
Run a job inside the CircleCI CLI container, via this orb's executor. In another job, use the orb to install the CLI.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
jobs:
use-executor:
executor: cli/default
steps:
- run: echo "this job is using the orb's default executor"
use-install-command:
docker:
- image: circleci/circleci-cli:latest
steps:
- cli/install
- run: echo "the CLI is now installed"
orbs:
cli: circleci/circleci-cli@x.y.z
version: 2.1
workflows:
cli-orb-example:
jobs:
- use-executor
- use-install-command
Install the CircleCI CLI
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
debug | Extra output for orb developers
| No | false | boolean |
install-dir | Directory in which to install the CircleCI CLI
| No | /usr/local/bin | string |
version | Version of CircleCI CLI to install, defaults to the latest release. If specifying a version other than latest, provide a full release tag, as listed at https://api.github.com/repos/CircleCI-Public/circleci-cli/tags, e.g., `v0.1.5581`.
| No | latest | string |
Run `circleci setup` to configure the CircleCI CLI (CLI must be installed first): https://circleci-public.github.io/circleci-cli/circleci_setup.html
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
host | Full URL of your CircleCI host (use the default value unless you are using a hosted installation of CircleCI)
| No | https://circleci.com | string |
token | Name of environment variable storing a CircleCI API token to use for CircleCI CLI commands that require authentication
| No | CIRCLECI_CLI_TOKEN | env_var_name |
The circleci-cli Docker image, which includes the CircleCI CLI
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
tag | What version of the CircleCI CLI Docker image? For full list, see https://hub.docker.com/r/circleci/circleci-cli/tags
| No | latest | string |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
commands:
install:
description: Install the CircleCI CLI
parameters:
debug:
default: false
description: |
Extra output for orb developers
type: boolean
install-dir:
default: /usr/local/bin
description: |
Directory in which to install the CircleCI CLI
type: string
version:
default: latest
description: |
Version of CircleCI CLI to install, defaults to the latest release. If specifying a version other than latest, provide a full release tag, as listed at https://api.github.com/repos/CircleCI-Public/circleci-cli/tags, e.g., `v0.1.5581`.
type: string
steps:
- run:
command: |
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
# grab CircleCI CLI version
if [[ "<<parameters.version>>" == "latest" ]]; then
# extract latest version from GitHub releases API
CIRCLECI_CLI_VERSION=$(curl -Ls -o /dev/null -w %{url_effective} "https://github.com/CircleCI-Public/circleci-cli/releases/latest" | sed 's:.*/::')
else
CIRCLECI_CLI_VERSION=<<parameters.version>>
echo "Selected version of CircleCI CLI is $CIRCLECI_CLI_VERSION"
fi
# check if CircleCI CLI needs to be installed
if command -v circleci<<^parameters.debug>> > /dev/null 2>&1<</parameters.debug>>; then
if circleci version | grep "${CIRCLECI_CLI_VERSION:1}"<<^parameters.debug>> > /dev/null 2>&1<</parameters.debug>>; then
echo "circleci $CIRCLECI_CLI_VERSION is already installed"
exit 0
else
echo "A different version of the CircleCI CLI is installed ($(circleci version)); updating it"
$SUDO rm -f "$(which circleci)"
curl -fLSs https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/master/install.sh | $SUDO bash
echo "CircleCI CLI version $(circleci --skip-update-check version) has been installed to $(which circleci)"
fi
fi
name: Install CircleCI CLI
setup:
description: |
Run `circleci setup` to configure the CircleCI CLI (CLI must be installed first): https://circleci-public.github.io/circleci-cli/circleci_setup.html
parameters:
host:
default: https://circleci.com
description: |
Full URL of your CircleCI host (use the default value unless you are using a hosted installation of CircleCI)
type: string
token:
default: CIRCLECI_CLI_TOKEN
description: |
Name of environment variable storing a CircleCI API token to use for CircleCI CLI commands that require authentication
type: env_var_name
steps:
- run:
command: |
circleci setup --no-prompt \
--host <<parameters.host>> \
--token $<<parameters.token>>
name: Configure CircleCI CLI
description: |
Install and configure the CircleCI command-line interface.
display:
home_url: https://circleci-public.github.io/circleci-cli/
source_url: https://github.com/CircleCI-Public/circleci-cli-orb
examples:
executor-command-example:
description: |
Run a job inside the CircleCI CLI container, via this orb's executor. In another job, use the orb to install the CLI.
usage:
jobs:
use-executor:
executor: cli/default
steps:
- run: echo "this job is using the orb's default executor"
use-install-command:
docker:
- image: circleci/circleci-cli:latest
steps:
- cli/install
- run: echo "the CLI is now installed"
orbs:
cli: circleci/circleci-cli@x.y.z
version: 2.1
workflows:
cli-orb-example:
jobs:
- use-executor
- use-install-command
executors:
default:
description: |
The circleci-cli Docker image, which includes the CircleCI CLI
docker:
- image: circleci/circleci-cli:<<parameters.tag>>
parameters:
tag:
default: latest
description: |
What version of the CircleCI CLI Docker image? For full list, see https://hub.docker.com/r/circleci/circleci-cli/tags
type: string
version: 2.1