Jenkins integration guide

Prev Next

CI/CD integration requires a cloud test execution environment.

This article explains how to integrate Autify Nexus with Jenkins. Specifically, it helps you understand how to run a test plan via the Autify Nexus API from a Jenkins node.

Prerequisites

You will need the following information from Autify Nexus:

  • Nexus server URL

  • API Client Secret

  • Test plan name

You will also need to install the jq command on your Jenkins node to run the code example on this page.

More information about the prerequisite information can be found in the table below.

Nexus server URL

The URL you use to login to Autify Nexus, for example, https://1234.cloud.autify.com

API Client secret

The client secret for the API client you created in Autify Nexus. See API Documentation for more information.

Test plan name

The case-sensitive name of the test plan you run in Jenkins. It must exactly match what is shown in Autify Nexus.

Save the client secret as a credential

The client secret should be stored as a credential in Jenkins.

  1. Click Manage Jenkins on the dashboard page

Screenshot_2025-04-15_at_10_29_05_2.png

  1. Click Credentials

Screenshot_2025-04-15_at_10_29_33.png

  1. Set the domain in which you want to add the secret

Screenshot_2025-04-15_at_10_29_54.png

  1. Click + Add Credentials

Screenshot_2025-04-15_at_10_30_24.png

  1. Under the Kind section, select the Secret text option

  2. In the Secret field, enter the API client secret

  3. Enter the credential name as ID (example: AUTIFY_CLIENT_SECRET)

  4. Click Create

Screenshot_2025-04-15_at_15_18_25.png

The credential that you have added can be seen on the credentials list.

Screenshot_2025-04-15_at_16_08_37.png

Create a job

  1. To define a new job, click + New Item on the dashboard.

Screenshot_2025-04-15_at_10_29_05.png

  1. Input the job name as the item name

  2. Choose Freestyle project as the item type

  3. Click OK

Screenshot_2025-04-15_at_10_22_05.png

  1. In the Build Environment section, select Use secret text(s) or file(s)

  2. Enter the name of the client secret you added in the previous section as Variable

  3. Select the credential for that client secret from the Credentials list

Screenshot_2025-04-15_at_16_13_13.png

  1. In the Build Steps section, select Execute shell as the build step

Screenshot_2025-04-15_at_10_22_56.png

  1. Enter the code in the code input field

For example, the following code runs the test plan found by name. The required information varies depending on your usage, so adjust it accordingly.

image.png

# ENV vars
SERVER_URL='https://<your-nexus-server>'
TEST_PLAN_NAME='<your-test-plan-name>'
# WORKSPACE_ID='<your-workspace-id>'  # Optional: specify if you have multiple workspaces

# Set authorization header using API client secret directly
AUTH_HEADER="Authorization: Bearer ${AUTIFY_CLIENT_SECRET}"
ACCEPT_HEADER='Accept: application/json'

# Get workspace ID (use first workspace if not specified)
res=$(
  curl \
    --silent \
    --show-error \
    --url "${SERVER_URL}/nexus/api/workspaces" \
    --header "$AUTH_HEADER" \
    --header "$ACCEPT_HEADER"
)

if [ -z "${WORKSPACE_ID:-}" ]; then
  WORKSPACE_ID=$(echo "$res" | jq -r '.[0].id')
fi

if [ -z "$WORKSPACE_ID" ] || [ "$WORKSPACE_ID" = "null" ]; then
  echo "Workspace not found. Response: ${res}"
  exit 1
fi

echo "Workspace ID: ${WORKSPACE_ID}"

# Get test plan ID
res=$(
  curl \
    --silent \
    --show-error \
    --url "${SERVER_URL}/nexus/api/workspaces/${WORKSPACE_ID}/testPlans" \
    --header "$AUTH_HEADER" \
    --header "$ACCEPT_HEADER"
)
TEST_PLAN_ID=$(echo "$res" | jq -r --arg NAME "$TEST_PLAN_NAME" '.[] | select(.name == $NAME) | .id')

if [ -z "$TEST_PLAN_ID" ]; then
  echo "Test plan '${TEST_PLAN_NAME}' not found. Response: ${res}"
  exit 1
fi

echo "Test plan ID for '${TEST_PLAN_NAME}': ${TEST_PLAN_ID}"

# Run the test plan
res=$(
  curl \
    --silent \
    --show-error \
    --request POST \
    --url "${SERVER_URL}/nexus/api/workspaces/${WORKSPACE_ID}/testPlans/${TEST_PLAN_ID}/run" \
    --header "$AUTH_HEADER" \
    --header "$ACCEPT_HEADER"
)
RESULT_ID=$(echo "$res" | jq -r '.resultId')

if [ "$RESULT_ID" = "null" ]; then
  echo "Failed to start test plan. Response: ${res}"
  exit 1
fi

echo "Test started. Result ID: ${RESULT_ID}"
echo "Waiting for test to complete..."

# Polling for result status
STATUS="QUEUED"
while [ "$STATUS" = "QUEUED" ] || [ "$STATUS" = "RUNNING" ]; do
  sleep 5
  res=$(
    curl \
      --silent \
      --show-error \
      --url "${SERVER_URL}/nexus/api/workspaces/${WORKSPACE_ID}/testResults/${RESULT_ID}/status" \
      --header "$AUTH_HEADER" \
      --header "$ACCEPT_HEADER"
  )
  STATUS=$(echo "$res" | jq -r '.status')

  if [ "$STATUS" = "null" ]; then
    echo "Failed to fetch result status. Response: ${res}"
    exit 1
  fi

  echo "Current status: $STATUS"
done

echo "Final status: $STATUS"
  1. Click Save to register the job

Run the job and verify it works

After defining a job, make sure if it works as expected.

  1. Click the job name on the dashboard

image.png

  1. Click Build Now to start the job

image.png

The build status can be seen in the left side of the page.

  1. Click the top item in the Builds pane

image.png

The output can be seen by clicking the Console Output.

image.png


The sample log "Final status: PASSED" indicates the test result in Autify Nexus. "PASSED" means the test succeeded. If the test fails, it is displayed as "FAILED".

The log "Finished: SUCCESS" appears on the last line of the log. This indicates the job finished without errors when communicating with the Autify Nexus API. Note that this status does not indicate whether the test result in Autify Nexus succeeded.

image.png