1. empear/codescene-ci-cd@1.0.0

empear/codescene-ci-cd@1.0.0

Partner
Sections
Run CodeScene Delta Analysis on commits and pull requests. See this orb's source: https://github.com/empear-analytics/codescene-ci-cd-orb
Created: June 23, 2019Version Published: June 27, 2019Releases: 1
Org Usage:
< 25

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: codescene-ci-cd: empear/codescene-ci-cd@1.0.0

Use codescene-ci-cd elements in your existing workflows and jobs.

Opt-in to use of uncertified orbs on your organization’s Security settings page.

Usage Examples

delta_analysis

Run CodeScene Delta Analysis. A context is used for specifying values for codescene-user, codescene-password and github-api-token by setting their default environment variables. The value for codescene-delta-analysis-url is project specific and is specified by setting the default environment variable in the project settings. The value it should be set to is available in the CodeScene project settings.

1 2 3 4 5 6 7 8 9 version: 2.1 orbs: codescene-ci-cd: empear/codescene-ci-cd@x.y.z workflows: version: 2 my-workflow: jobs: - codescene-ci-cd/run-delta-analysis: context: codescene-ci-cd

delta_analysis_with_custom_values

Run CodeScene Delta Analysis. Custom values for parameters are specified directly on the job.

1 2 3 4 5 6 7 8 9 10 11 12 version: 2.1 orbs: codescene-ci-cd: empear/codescene-ci-cd@x.y.z workflows: version: 2 my-workflow: jobs: - codescene-ci-cd/run-delta-analysis: codescene-delta-analysis-url: ${MY_DELTA_ANALYSIS_URL_ENV_VAR} codescene-user: ${MY_CODESCENE_USER_ENV_VAR} codescene-password: ${MY_CODESCENE_PASSWORD_ENV_VAR} github-api-token: ${MY_GITHUB_API_TOKEN_ENV_VAR}

Jobs

run-delta-analysis

Run CodeScene Delta Analysis. Requires setting the codescene-delta-analysis-url, codescene-user, codescene-password and github-api-token parameters, either explicitly or by setting the corresponding environment variables using the CircleCI UI

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
codescene-delta-analysis-url
The CodeScene delta analysis API URL. Set the parameter or use the CircleCI UI to add the value to the 'CODESCENE_DELTA_ANALYSIS_URL' env variable.
No
${CODESCENE_DELTA_ANALYSIS_URL}
string
codescene-user
The name of a CodeScene user. Set the parameter or use the CircleCI UI to add the value to the 'CODESCENE_USER' env variable.
No
${CODESCENE_USER}
string
codescene-password-key
The name of an env variable containing the codescene password. Use the CircleCI UI to add a value to the env variable.
No
CODESCENE_PASSWORD
env_var_name
coupling-threshold-percent
The coupling threshold (percent) used for analysis.
No
80
integer
risk-threshold
The risk threshold (1-10) used for the high risk gate.
No
7
integer
http-timeout
The timeout in ms for http calls.
No
30000
integer
github-api-url
The GitHub API URL
No
https://api.github.com
string
github-api-token-key
The name of an env variable containing a GitHub API token with permissions to add comments to merge requests. Use the CircleCI UI to add a value to the env variable.
No
GITHUB_API_TOKEN
env_var_name

Executors

codescene-ci-cd-executor

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
version
-
No
1.1.1
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 # This code is licensed from CircleCI to the user under the MIT license. # See here for details: https://circleci.com/developer/orbs/licensing version: 2.1 description: > Run CodeScene Delta Analysis on commits and pull requests. See this orb's source: https://github.com/empear-analytics/codescene-ci-cd-orb examples: delta_analysis: description: > Run CodeScene Delta Analysis. A context is used for specifying values for codescene-user, codescene-password and github-api-token by setting their default environment variables. The value for codescene-delta-analysis-url is project specific and is specified by setting the default environment variable in the project settings. The value it should be set to is available in the CodeScene project settings. usage: version: 2.1 orbs: codescene-ci-cd: empear/codescene-ci-cd@x.y.z workflows: version: 2 my-workflow: jobs: - codescene-ci-cd/run-delta-analysis: context: codescene-ci-cd delta_analysis_with_custom_values: description: > Run CodeScene Delta Analysis. Custom values for parameters are specified directly on the job. usage: version: 2.1 orbs: codescene-ci-cd: empear/codescene-ci-cd@x.y.z workflows: version: 2 my-workflow: jobs: - codescene-ci-cd/run-delta-analysis: codescene-delta-analysis-url: ${MY_DELTA_ANALYSIS_URL_ENV_VAR} codescene-user: ${MY_CODESCENE_USER_ENV_VAR} codescene-password: ${MY_CODESCENE_PASSWORD_ENV_VAR} github-api-token: ${MY_GITHUB_API_TOKEN_ENV_VAR} jobs: run-delta-analysis: description: > Run CodeScene Delta Analysis. Requires setting the codescene-delta-analysis-url, codescene-user, codescene-password and github-api-token parameters, either explicitly or by setting the corresponding environment variables using the CircleCI UI parameters: codescene-delta-analysis-url: description: > The CodeScene delta analysis API URL. Set the parameter or use the CircleCI UI to add the value to the 'CODESCENE_DELTA_ANALYSIS_URL' env variable. type: string default: ${CODESCENE_DELTA_ANALYSIS_URL} codescene-user: description: > The name of a CodeScene user. Set the parameter or use the CircleCI UI to add the value to the 'CODESCENE_USER' env variable. type: string default: ${CODESCENE_USER} codescene-password-key: description: > The name of an env variable containing the codescene password. Use the CircleCI UI to add a value to the env variable. type: env_var_name default: CODESCENE_PASSWORD coupling-threshold-percent: description: > The coupling threshold (percent) used for analysis. type: integer default: 80 risk-threshold: description: > The risk threshold (1-10) used for the high risk gate. type: integer default: 7 http-timeout: description: > The timeout in ms for http calls. type: integer default: 30000 github-api-url: description: > The GitHub API URL type: string default: https://api.github.com github-api-token-key: description: > The name of an env variable containing a GitHub API token with permissions to add comments to merge requests. Use the CircleCI UI to add a value to the env variable. type: env_var_name default: GITHUB_API_TOKEN executor: codescene-ci-cd-executor steps: - checkout - run: name: CodeScene Delta Analysis command: | if [[ -z "<< parameters.codescene-delta-analysis-url >>" ]] ; then echo "No value specified for codescene-delta-analysis-url!" exit 1 fi if [[ -z "<< parameters.codescene-user >>" ]] ; then echo "No value specified for codescene-user!" exit 1 fi if [[ -z "<< parameters.codescene-password-key >>" ]] ; then echo "No value specified for codescene-password-key!" exit 1 fi if [[ -z "${<< parameters.codescene-password-key >>}" ]] ; then echo "No value specified for << parameters.codescene-password-key >>!" exit 1 fi if [[ -z "<< parameters.coupling-threshold-percent >>" ]] ; then echo "No value specified for coupling-threshold-percent!" exit 1 fi if [[ -z "<< parameters.risk-threshold >>" ]] ; then echo "No value specified for risk-threshold!" exit 1 fi if [[ -z "<< parameters.http-timeout >>" ]] ; then echo "No value specified for http-timeout!" exit 1 fi if [[ -z "<< parameters.github-api-url >>" ]] ; then echo "No value specified for github-api-url!" exit 1 fi if [[ -z "<< parameters.github-api-token-key >>" ]] ; then echo "No value specified for github-api-token-key!" exit 1 fi if [[ -z "${<< parameters.github-api-token-key >>}" ]] ; then echo "No value specified for << parameters.github-api-token-key >>!" exit 1 fi if [[ -z ${CIRCLE_PULL_REQUEST} ]] ; then PREVIOUS_COMMIT=$(git rev-parse HEAD^) codescene-ci-cd.sh \ --codescene-delta-analysis-url << parameters.codescene-delta-analysis-url >> \ --codescene-user << parameters.codescene-user >> \ --codescene-password ${<< parameters.codescene-password-key >>} \ --codescene-repository ${CIRCLE_PROJECT_REPONAME} \ --fail-on-failed-goal \ --fail-on-declining-code-health \ --analyze-individual-commits \ --coupling-threshold-percent << parameters.coupling-threshold-percent >> \ --risk-threshold << parameters.risk-threshold >> \ --current-commit ${CIRCLE_SHA1} \ --previous-commit ${PREVIOUS_COMMIT} \ --http-timeout << parameters.http-timeout >> \ --log-result; else PULL_REQUEST_ID=${CIRCLE_PULL_REQUEST##*/} if [[ -z ${PULL_REQUEST_ID} ]] ; then echo "Failed to get pull request id!" exit 1 fi PR_URL="<< parameters.github-api-url >>/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls/$PULL_REQUEST_ID" # The extra "" in the header is necessary for passing yaml parsing (colon-space is not valid) TARGET_BRANCH=$(curl -s -X GET -G $PR_URL -H "Authorization:"" token ${<< parameters.github-api-token-key >>}" | jq '.base.ref' | tr -d '"') if [[ -z ${TARGET_BRANCH} ]] ; then echo "Failed to get target branch!" exit 1 fi codescene-ci-cd.sh \ --codescene-delta-analysis-url << parameters.codescene-delta-analysis-url >> \ --codescene-user << parameters.codescene-user >> \ --codescene-password ${<< parameters.codescene-password-key >>} \ --codescene-repository ${CIRCLE_PROJECT_REPONAME} \ --fail-on-failed-goal \ --fail-on-declining-code-health \ --analyze-branch-diff \ --coupling-threshold-percent << parameters.coupling-threshold-percent >> \ --risk-threshold << parameters.risk-threshold >> \ --current-commit ${CIRCLE_SHA1} \ --base-revision ${TARGET_BRANCH} \ --create-github-comment \ --github-api-url << parameters.github-api-url >> \ --github-api-token ${<< parameters.github-api-token-key >>} \ --github-owner ${CIRCLE_PROJECT_USERNAME} \ --github-repo ${CIRCLE_PROJECT_REPONAME} \ --github-pull-request-id ${PULL_REQUEST_ID} \ --http-timeout << parameters.http-timeout >> \ --log-result; fi executors: codescene-ci-cd-executor: parameters: version: type: string default: "1.1.1" docker: - image: empear/codescene-ci-cd:<<parameters.version>> entrypoint: ""
Developer Updates
Get tips to optimize your builds
Or join our research panel and give feedback
By submitting this form, you are agreeing to ourTerms of UseandPrivacy Policy.