Jenkins integration guide

Prev Next

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:

  • A Nexus server URL

  • Organization ID

  • Client ID

  • Client Secret

  • The workspace ID that your test plan belongs to

  • A 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

Organization ID

Found at the beginning of your Nexus server URL. For example, if the URL is https://1234.cloud.autify.com then the organization ID would be 1234

Client ID

The client ID of the API client you created in Autify Nexus. See [LINK HERE] for more information.

Client secret

The client secret for the API client you created in Autify Nexus. See [LINK HERE] for more information.

Workspace ID

You can find this information using the workspaces API. [LINK]

Test plan name

Case-sensitive name of the test plan you want to execute in Jenkins. It should be exactly the same as it appears in Autify Nexus.

Store 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. Select the Secret text option under the "Kind" section

  2. Input your client secret into the "Secret" field

  3. Input the name of the credential as the "ID", for 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. Check Use secret text(s) or file(s) in the "Environment" section

  2. Input the name of the client secret that you added in the previous section as a "Variable"

  3. Choose the credential for that client secret from the list in the "Credentials"

Screenshot_2025-04-15_at_16_13_13.png

  1. Select Execute shell as the build step in the "Build Steps" section

Screenshot_2025-04-15_at_10_22_56.png

  1. Put the code in the code input field

For example, the following code is to run a test plan found by the name. Please note that the information will be different depending on your use case.

image.png

# ENV vars
AUTIFY_CLIENT_ID='<your-client-id>'
SERVER_URL='https://<your-nexus-server>'
ORGANIZATION_ID='<your-org-id>'
WORKSPACE_ID='<your-workspace-id>'
TEST_PLAN_NAME='<your-test-plan-name>'

# Get access token
res=$(
  curl \
    --silent \
    --location "${SERVER_URL}/auth/realms/${ORGANIZATION_ID}/protocol/openid-connect/token" \
    --data-urlencode "client_id=${AUTIFY_CLIENT_ID}" \
    --data-urlencode "client_secret=${AUTIFY_CLIENT_SECRET}" \
    --data-urlencode 'grant_type=client_credentials' \
    -k
)
ACCESS_TOKEN=$(echo $res | jq -r '.access_token')

if [ "$ACCESS_TOKEN" = "null" ]; then
  echo "Failed to authenticate. Response: ${res}"
  exit 1
fi

AUTH_HEADER="Authorization: Bearer ${ACCESS_TOKEN}"
ACCEPT_HEADER='Accept: application/json'

# Get test plan ID
res=$(
  curl \
    --silent \
    --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 \
    --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" -o "$STATUS" = "RUNNING" ]; do
  sleep 5
  res=$(
    curl \
      --silent \
      --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

Execute the Job to Confirm Behavior

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 log "Final status: PASSED" in this example shows the test result in Autify Nexus. "PASSED" means the test result was successful. "FAILED" is shown if the test result failed.

The log "Finished: SUCCESS" should be displayed at the final line in the log. This indicates that the job successfully finished without errors when communicating with the Autify Nexus API. Note that this status does not indicate that the test result in Autify Nexus was a success.

image.png