1. circleci/heroku@2.0.0

circleci/heroku@2.0.0

Certified
Sections
Easily install and use the Heroku CLI with CircleCI to build, test, and deploy your applications to Heroku.
Created: August 20, 2018Version Published: September 27, 2022Releases: 22
Org Usage:
411

Orb Quick Start Guide

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: heroku: circleci/heroku@2.0.0

Use heroku elements in your existing workflows and jobs.

Usage Examples

create_review_app

A sample job that deploys a review app to Heroku, that does not run on the main "deployed" branch. Assumes that your CircleCI token is stored in $CIRCLECI_API_KEY and Heroku's API key under $HEROKU_API_KEY.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 version: '2.1' orbs: heroku: circleci/heroku@2.0 jobs: create-review-app: executor: heroku/default steps: - checkout - run: command: tar -czvf my-project.tar.gz ~/project name: Bundle our project project working_directory: ~/ - store_artifacts: path: ~/my-project.tar.gz - heroku/create-review: artifact-pattern: '*.tar.gz' pipeline: PIPELINE-UUID workflows: heroku_review: jobs: - create-review-app: filters: branches: ignore: main

use_heroku_commands

'A simple example of a job utilizing the `install` and `deploy-via-git` commands.'

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 version: '2.1' orbs: heroku: circleci/heroku@2.0 jobs: deploy: executor: heroku/default steps: - checkout - heroku/install - run: command: > echo "The command above installs Heroku, the command below deploys. What you do inbetween is up to you!" - heroku/deploy-via-git workflows: heroku_deploy: jobs: - deploy

use_heroku_job

Easily deploy to Heroku with a single job supplied by this orb.

1 2 3 4 5 6 7 8 9 10 11 version: '2.1' orbs: heroku: circleci/heroku@2.0 workflows: heroku_deploy: jobs: - heroku/deploy-via-git: post-steps: - run: your-database-migration-command pre-steps: - run: command-that-run-before-deploying

Jobs

deploy-via-git

Use Git to push the changes of the current tag or branch to Heroku for deployment.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
api-key
The name of the environment variable containing your Heroku API Key.
No
HEROKU_API_KEY
env_var_name
app-name
Add the name of your application to an environment variable with this name.
No
HEROKU_APP_NAME
string
branch
Deploy the given branch. The default value is your current branch. Accepts strings which may contain an environment variable.
No
$CIRCLE_BRANCH
string
force
Whether or not to force the git push (i.e. `git push -f`). Defaults to false.
No
false
boolean
maintenance-mode
Use this to automatically enable maintenance mode before pre-deploy steps and have it disabled after post-deploy steps have been run.
No
false
boolean
no_output_timeout
Allows you to specify the no_output_timeout for the `git push` to heroku. Defaults to 10m.
No
10m
string
post-deploy
A list of post-deploy steps that are run after deployment. This would be an ideal place to scale any processes back up.
No
[]
steps
pre-deploy
A list of pre-deploy steps that are run before deployment. This would be an ideal place to scale any processes down.
No
[]
steps
tag
Deploy the given tag. The default value is your current tag.
No
$CIRCLE_TAG
string

push-docker-image

Quickly and easily take the changes to this branch and deploy them to Heroku automatically with this job.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
app-name
The name of your Heroku App. For backwards compatibility the literal value `$HEROKU_APP_NAME` is the default, so you can easily use this command by setting an environment variable called HEROKU_APP_NAME
No
$HEROKU_APP_NAME
string
maintenance-mode
Use this to automatically enable maintenance mode before pre-deploy steps and have it disabled after post-deploy steps have been run.
No
false
boolean
post-deploy
A list of post-deploy steps that are run after deployment. This would be an ideal place to scale any processes back up.
No
[]
steps
pre-deploy
A list of pre-deploy steps that are run before deployment. This would be an ideal place to scale any processes down.
No
[]
steps

Commands

check-authentication

Verifies the Heroku API key has been added so we can authenticate.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
print-whoami
Print the result of heroku auth:whoami.
No
false
boolean

create-review

Deploys a new review app. Artifacts for creating the review should be saved in a prior step.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
artifact-pattern
RegEx or filename of artifact to deploy to Heroku.
Yes
-
string
circleci-api-key
Environment variable containing the Heroku API key
No
CIRCLE_TOKEN
env_var_name
heroku-api-key
The name of the environment variable containing your Heroku API Key.
No
HEROKU_API_KEY
env_var_name
pipeline
Heroku pipeline to deploy with (UUID).
Yes
-
string

deploy-via-git

Use Git to push the changes of the current tag or branch to Heroku for deployment.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
api-key
The name of the environment variable containing your Heroku API Key.
No
HEROKU_API_KEY
env_var_name
app-name
The name of your Heroku app. May also refer to an environment variable.
No
$HEROKU_APP_NAME
string
branch
Deploy the given branch. The default value is your current branch. Accepts strings which may contain an environment variable.
No
$CIRCLE_BRANCH
string
force
Whether or not to force the git push (i.e. `git push -f`). Defaults to false.
No
false
boolean
maintenance-mode
Use this to automatically enable maintenance mode before pre-deploy steps and have it disabled after post-deploy steps have been run.
No
false
boolean
no_output_timeout
Allows you to specify the no_output_timeout for the `git push` to heroku. Defaults to 10m.
No
10m
string
tag
Deploy the given tag. The default value is your current tag.
No
$CIRCLE_TAG
string

install

Download and install the Heroku CLI. Will be skipped if the CLI is already installed in the system.

Show command Source

push-docker-image

Push a Docker image to the Heroku Docker registry.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
api-key
The name of the environment variable containing your Heroku API Key.
No
HEROKU_API_KEY
env_var_name
app-name
The name of your Heroku app. May also refer to an environment variable.
No
$HEROKU_APP_NAME
string
no_output_timeout
Allows you to specify the no_output_timeout for the `git push` to heroku. Defaults to 10m.
No
10m
string
process-types
Process types.
No
''
string
recursive
Push all Dockerfiles in the directory to Heroku.
No
false
boolean

release-docker-image

Release a Docker image from the Heroku Docker registry.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
api-key
The name of the environment variable containing your Heroku API Key.
No
HEROKU_API_KEY
env_var_name
app-name
The name of your Heroku app. May also refer to an environment variable.
No
$HEROKU_APP_NAME
string
no_output_timeout
Allows you to specify the no_output_timeout for the `git push` to heroku. Defaults to 10m.
No
10m
string
process-types
Process types.
No
web
string

Executors

default

A highly efficient and cached Ubuntu-based image. Consider using this executor or selecting an image for your language https://hub.docker.com/r/cimg/

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
tag
Pick a specific cimg/base tag: https://hub.docker.com/r/cimg/base/tags
No
current
string

Orb Source

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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 # This code is licensed from CircleCI to the user under the MIT license. # See here for details: https://circleci.com/developer/ja/orbs/licensing version: 2.1 description: | Easily install and use the Heroku CLI with CircleCI to build, test, and deploy your applications to Heroku. display: home_url: https://www.heroku.com/ source_url: https://github.com/CircleCI-Public/heroku-orb commands: check-authentication: description: | Verifies the Heroku API key has been added so we can authenticate. parameters: print-whoami: default: false description: Print the result of heroku auth:whoami. type: boolean steps: - run: command: | #!/bin/bash if [[ $HEROKU_API_KEY == "" ]]; then echo "No Heroku API key set, please set the HEROKU_API_KEY environment variable." echo "This can be found by running the $(heroku auth:token) command locally." exit 1 else echo "Heroku API key found." fi environment: PARAM_WHOAMI: <<parameters.print-whoami>> name: Verify HEROKU_API_KEY is set create-review: description: | Deploys a new review app. Artifacts for creating the review should be saved in a prior step. parameters: artifact-pattern: description: RegEx or filename of artifact to deploy to Heroku. type: string circleci-api-key: default: CIRCLE_TOKEN description: Environment variable containing the Heroku API key type: env_var_name heroku-api-key: default: HEROKU_API_KEY description: The name of the environment variable containing your Heroku API Key. type: env_var_name pipeline: description: Heroku pipeline to deploy with (UUID). type: string steps: - run: command: | #!/bin/bash CIRCLE_TOKEN_FETCHED=$(eval echo "${PARAM_CIRCLE_TOKEN}") HEROKU_KEY_FETCHED=$(eval echo "${PARAM_HEROKU_KEY}") if [ -z "$CIRCLE_TOKEN_FETCHED" ]; then echo "CircleCI token is not set" exit 1 fi if [ -z "$HEROKU_KEY_FETCHED" ]; then echo "Heroku API key is not set" exit 1 fi function get_artifacts { artifact_res_tmpfile=$(mktemp) artifact_request=$(curl -s -o "${artifact_res_tmpfile}" -w "%{http_code}" --retry 5 \ --url "https://circleci.com/api/v2/project/gh/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_BUILD_NUM}/artifacts" \ --header "Circle-Token: ${CIRCLE_TOKEN_FETCHED}") artifact_results=$(cat "${artifact_res_tmpfile}") if [ "${artifact_request}" != "200" ]; then echo "Error fetching artifacts" echo echo "$artifact_results" exit 1 fi for row in $(echo "${artifact_results}" | jq -c '.items[]'); do _jq() { echo "${row}" | jq -r "${1}" } # shellcheck disable=SC2053 if [[ $(_jq '.path') == $PARAM_ARTIFACT_PATTERN ]]; then ARTIFACT_LOCATION=$(_jq '.url') echo "Using ${ARTIFACT_LOCATION} as artifact." return 0 fi echo "No artifacts found!" echo echo "$artifact_results" return 1 done } function create { heroku_request=$(curl -n -X POST 'https://api.heroku.com/review-apps' \ -d "{ \"branch\": \"${CIRCLE_BRANCH}\", \"pipeline\": \"${HEROKU_PIPELINE}\", \"source_blob\": { \"url\": \"${ARTIFACT_LOCATION}?circle-token=${CIRCLE_TOKEN_FETCHED}\", \"version\": \"${CIRCLE_SHA1}\" } }" \ -H "Content-Type: application/json" \ -H "Accept: application/vnd.heroku+json; version=3" \ -H "Authorization: Bearer ${HEROKU_KEY_FETCHED}") echo "$heroku_request" | jq -C } get_artifacts create environment: PARAM_ARTIFACT_PATTERN: <<parameters.artifact-pattern>> PARAM_CIRCLE_TOKEN: <<parameters.circleci-api-key>> PARAM_HEROKU_KEY: <<parameters.heroku-api-key>> PARAM_HEROKU_PIPELINE: <<parameters.pipeline>> name: Create new Heroku Review app deploy-via-git: description: | Use Git to push the changes of the current tag or branch to Heroku for deployment. parameters: api-key: default: HEROKU_API_KEY description: The name of the environment variable containing your Heroku API Key. type: env_var_name app-name: default: $HEROKU_APP_NAME description: The name of your Heroku app. May also refer to an environment variable. type: string branch: default: $CIRCLE_BRANCH description: Deploy the given branch. The default value is your current branch. Accepts strings which may contain an environment variable. type: string force: default: false description: Whether or not to force the git push (i.e. `git push -f`). Defaults to false. type: boolean maintenance-mode: default: false description: Use this to automatically enable maintenance mode before pre-deploy steps and have it disabled after post-deploy steps have been run. type: boolean no_output_timeout: default: 10m description: Allows you to specify the no_output_timeout for the `git push` to heroku. Defaults to 10m. type: string tag: default: $CIRCLE_TAG description: Deploy the given tag. The default value is your current tag. type: string steps: - when: condition: << parameters.maintenance-mode >> steps: - run: command: heroku maintenance:on --app << parameters.app-name >> name: Turn ON maintenance mode. - run: command: |- #!/bin/bash PARAM_DEPLOY_TAG=$(eval echo "${PARAM_DEPLOY_TAG}") PARAM_APP_NAME=$(eval echo "${PARAM_APP_NAME}") PARAM_HEROKU_API_KEY=${!PARAM_HEROKU_API_KEY} PARAM_DEPLOY_BRANCH=$(eval echo "${PARAM_DEPLOY_BRANCH}") if [ "$PARAM_FORCE_PUSH" == "1" ];then force="-f" fi heroku_url="https://heroku:${PARAM_HEROKU_API_KEY}@git.heroku.com/${PARAM_APP_NAME}.git" echo "$heroku_url" > /tmp/orblog.txt if [ -n "$PARAM_DEPLOY_BRANCH" ]; then git push $force "$heroku_url" "$PARAM_DEPLOY_BRANCH:main" elif [ -n "$PARAM_DEPLOY_TAG" ]; then git push $force "$heroku_url" "${PARAM_DEPLOY_TAG}^{}:main" else echo "No branch or tag found." exit 1 fi environment: PARAM_APP_NAME: <<parameters.app-name>> PARAM_DEPLOY_BRANCH: <<parameters.branch>> PARAM_DEPLOY_TAG: <<parameters.tag>> PARAM_FORCE_PUSH: <<parameters.force>> PARAM_HEROKU_API_KEY: <<parameters.api-key>> PARAM_MAINTENANCE_MODE: <<parameters.maintenance-mode>> PARAM_NO_OUTPUT_TIMEOUT: <<parameters.no_output_timeout>> name: Deploy branch or tag to Heroku via git push no_output_timeout: << parameters.no_output_timeout >> - when: condition: << parameters.maintenance-mode >> steps: - run: command: heroku maintenance:off --app << parameters.app-name >> name: Turn OFF maintenance mode. install: description: | Download and install the Heroku CLI. Will be skipped if the CLI is already installed in the system. steps: - run: command: |- #!/bin/bash if ! command -v heroku &> /dev/null; then curl https://cli-assets.heroku.com/install.sh | sh else echo "Heroku is already installed. No operation was performed." fi name: Install Heroku CLI (If not installed) push-docker-image: description: | Push a Docker image to the Heroku Docker registry. parameters: api-key: default: HEROKU_API_KEY description: The name of the environment variable containing your Heroku API Key. type: env_var_name app-name: default: $HEROKU_APP_NAME description: The name of your Heroku app. May also refer to an environment variable. type: string no_output_timeout: default: 10m description: Allows you to specify the no_output_timeout for the `git push` to heroku. Defaults to 10m. type: string process-types: default: "" description: Process types. type: string recursive: default: false description: Push all Dockerfiles in the directory to Heroku. type: boolean steps: - run: command: heroku container:login name: Login to Heroku Docker image registry - run: command: |- #!/bin/bash PARAM_HEROKU_API_KEY="${!PARAM_HEROKU_API_KEY}" if [ "$PARAM_RECURSIVE" == "1" ];then set -- "$@" --resursive fi set -x heroku container:push -a "$PARAM_APP_NAME" "$@" "$PARAM_PROCESS_TYPES" set +x environment: PARAM_APP_NAME: <<parameters.app-name>> PARAM_HEROKU_API_KEY: <<parameters.api-key>> PARAM_PROCESS_TYPES: <<parameters.process-types>> PARAM_RECURSIVE: <<parameters.recursive>> name: Push Docker image to Heroku no_output_timeout: << parameters.no_output_timeout >> release-docker-image: description: | Release a Docker image from the Heroku Docker registry. parameters: api-key: default: HEROKU_API_KEY description: The name of the environment variable containing your Heroku API Key. type: env_var_name app-name: default: $HEROKU_APP_NAME description: The name of your Heroku app. May also refer to an environment variable. type: string no_output_timeout: default: 10m description: Allows you to specify the no_output_timeout for the `git push` to heroku. Defaults to 10m. type: string process-types: default: web description: Process types. type: string steps: - run: command: heroku container:login name: Login to Heroku Docker image registry - run: command: |- #!/bin/bash heroku container:release -a "$PARAM_APP_NAME" "$PARAM_PROCESS_TYPES" environment: PARAM_APP_NAME: <<parameters.app-name>> PARAM_PROCESS_TYPES: <<parameters.process-types>> name: Release Docker image to Heroku no_output_timeout: << parameters.no_output_timeout >> executors: default: description: | A highly efficient and cached Ubuntu-based image. Consider using this executor or selecting an image for your language https://hub.docker.com/r/cimg/ docker: - image: cimg/base:<<parameters.tag>> parameters: tag: default: current description: | Pick a specific cimg/base tag: https://hub.docker.com/r/cimg/base/tags type: string jobs: deploy-via-git: description: | Use Git to push the changes of the current tag or branch to Heroku for deployment. executor: default parameters: api-key: default: HEROKU_API_KEY description: The name of the environment variable containing your Heroku API Key. type: env_var_name app-name: default: HEROKU_APP_NAME description: Add the name of your application to an environment variable with this name. type: string branch: default: $CIRCLE_BRANCH description: Deploy the given branch. The default value is your current branch. Accepts strings which may contain an environment variable. type: string force: default: false description: Whether or not to force the git push (i.e. `git push -f`). Defaults to false. type: boolean maintenance-mode: default: false description: Use this to automatically enable maintenance mode before pre-deploy steps and have it disabled after post-deploy steps have been run. type: boolean no_output_timeout: default: 10m description: Allows you to specify the no_output_timeout for the `git push` to heroku. Defaults to 10m. type: string post-deploy: default: [] description: A list of post-deploy steps that are run after deployment. This would be an ideal place to scale any processes back up. type: steps pre-deploy: default: [] description: A list of pre-deploy steps that are run before deployment. This would be an ideal place to scale any processes down. type: steps tag: default: $CIRCLE_TAG description: Deploy the given tag. The default value is your current tag. type: string steps: - install - check-authentication - checkout - steps: << parameters.pre-deploy >> - deploy-via-git: api-key: << parameters.api-key >> app-name: << parameters.app-name >> branch: << parameters.branch >> force: << parameters.force >> maintenance-mode: << parameters.maintenance-mode >> no_output_timeout: << parameters.no_output_timeout >> tag: << parameters.tag >> - steps: << parameters.post-deploy >> push-docker-image: description: | Quickly and easily take the changes to this branch and deploy them to Heroku automatically with this job. executor: default parameters: app-name: default: $HEROKU_APP_NAME description: The name of your Heroku App. For backwards compatibility the literal value `$HEROKU_APP_NAME` is the default, so you can easily use this command by setting an environment variable called HEROKU_APP_NAME type: string maintenance-mode: default: false description: Use this to automatically enable maintenance mode before pre-deploy steps and have it disabled after post-deploy steps have been run. type: boolean post-deploy: default: [] description: A list of post-deploy steps that are run after deployment. This would be an ideal place to scale any processes back up. type: steps pre-deploy: default: [] description: A list of pre-deploy steps that are run before deployment. This would be an ideal place to scale any processes down. type: steps steps: - install - check-authentication - checkout - steps: << parameters.pre-deploy >> - push-docker-image: app-name: << parameters.app-name >> process-types: web - release-docker-image: app-name: << parameters.app-name >> process-types: web - steps: << parameters.post-deploy >> examples: create_review_app: description: | A sample job that deploys a review app to Heroku, that does not run on the main "deployed" branch. Assumes that your CircleCI token is stored in $CIRCLECI_API_KEY and Heroku's API key under $HEROKU_API_KEY. usage: version: "2.1" orbs: heroku: circleci/heroku@2.0 jobs: create-review-app: executor: heroku/default steps: - checkout - run: command: tar -czvf my-project.tar.gz ~/project name: Bundle our project project working_directory: ~/ - store_artifacts: path: ~/my-project.tar.gz - heroku/create-review: artifact-pattern: '*.tar.gz' pipeline: PIPELINE-UUID workflows: heroku_review: jobs: - create-review-app: filters: branches: ignore: main use_heroku_commands: description: | 'A simple example of a job utilizing the `install` and `deploy-via-git` commands.' usage: version: "2.1" orbs: heroku: circleci/heroku@2.0 jobs: deploy: executor: heroku/default steps: - checkout - heroku/install - run: command: | echo "The command above installs Heroku, the command below deploys. What you do inbetween is up to you!" - heroku/deploy-via-git workflows: heroku_deploy: jobs: - deploy use_heroku_job: description: | Easily deploy to Heroku with a single job supplied by this orb. usage: version: "2.1" orbs: heroku: circleci/heroku@2.0 workflows: heroku_deploy: jobs: - heroku/deploy-via-git: post-steps: - run: your-database-migration-command pre-steps: - run: command-that-run-before-deploying
開発者向け最新情報
ビルド最適化のためのヒントを手に入れましょう。
または、リサーチパネルに参加して フィードバックをお寄せください。
このフォームを送信することで、当社の利用規約およびプライバシーポリシーに同意したものと見なされます。