Skip to main content

Jenkins

The fore ai Jenkins integration runs tests using the CJ Action docker image. Any Jenkins agent with Docker available can run fore ai tests.

Prerequisites

1. Docker on the Jenkins agent

The Jenkins agent that runs the pipeline must have Docker installed and accessible.

2. Add credentials in Jenkins

Go to Manage JenkinsCredentialsGlobalAdd Credentials and add the following as Secret text credentials:

Credential IDValue
CJ_SERVICE_ACCOUNT_KEYYour fore ai service account key
CJ_TEST_IDID of the test to run (for single-test pipelines)
CJ_TEST_SUITE_IDID of the test suite to run (for suite pipelines)
note

Make sure there are no leading or trailing spaces in credential values - these will cause authentication failures.

Run a single test

pipeline {
agent any
stages {
stage('Run fore ai Test') {
steps {
withCredentials([
string(credentialsId: 'CJ_SERVICE_ACCOUNT_KEY', variable: 'SERVICE_ACCOUNT_KEY'),
string(credentialsId: 'CJ_TEST_ID', variable: 'TEST_ID')
]) {
sh 'docker run --rm -e "INPUT_SERVICE_ACCOUNT_KEY=$SERVICE_KEY" -e "INPUT_TEST_ID=$TEST_ID" foreai/cj-action:latest'
}
}
}
}
}

Run a test suite

pipeline {
agent any
stages {
stage('Run fore ai Test Suite') {
steps {
withCredentials([
string(credentialsId: 'CJ_SERVICE_ACCOUNT_KEY', variable: 'SERVICE_ACCOUNT_KEY'),
string(credentialsId: 'CJ_TEST_SUITE_ID', variable: 'TEST_SUITE_ID')
]) {
sh 'docker run --rm -e "INPUT_SERVICE_ACCOUNT_KEY=$SERVICE_KEY" -e "INPUT_TEST_SUITE_ID=$SUITE_ID" -e "INPUT_WAIT_TIMEOUT_SECONDS=360" -e "INPUT_WEBSITE_URL_OVERRIDE=https://staging.my-app.com" -e "INPUT_PARAMS_OVERRIDE={\"param1\":\"value1\",\"param2\":\"value2\"}" foreai/cj-action:latest'
}
}
}
}
}

Available inputs

Pass each input as a Docker environment variable using -e "INPUT_<NAME>=<value>".

Environment variableRequiredDefaultDescription
INPUT_TEST_IDNo*ID of the test to run. Provide either this or INPUT_TEST_SUITE_ID.
INPUT_TEST_SUITE_IDNo*ID of the test suite to run.
INPUT_SERVICE_ACCOUNT_KEYYesYour fore ai service account key.
INPUT_WAIT_TIMEOUT_SECONDSNo300Max seconds to wait for completion. Must be between 30 and 900.
INPUT_WEBSITE_URL_OVERRIDENoOverride the base website URL used during test execution.
INPUT_PARAMS_OVERRIDENoOverride default parameter values. Must be a valid JSON string with string keys and values.
INPUT_BROWSER_TYPE_OVERRIDENochromiumBrowser engine: chromium, firefox, or webkit.
INPUT_CREATE_ISSUE_ON_FAILURENofalseIf true, creates an issue on test failure (requires additional token configuration).

* Either INPUT_TEST_ID or INPUT_TEST_SUITE_ID must be provided.