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, |
Organization ID | Found at the beginning of your Nexus server URL. For example, if the URL is |
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.
Click Manage Jenkins on the dashboard page
Click Credentials
Set the domain in which you want to add the secret
Click + Add Credentials
Select the Secret text option under the "Kind" section
Input your client secret into the "Secret" field
Input the name of the credential as the "ID", for example, "AUTIFY_CLIENT_SECRET"
Click Create
The credential that you have added can be seen on the credentials list.
Create a job
To define a new job, click + New Item on the dashboard.
Input the job name as the item name
Choose Freestyle project as the item type
Click OK
Check Use secret text(s) or file(s) in the "Environment" section
Input the name of the client secret that you added in the previous section as a "Variable"
Choose the credential for that client secret from the list in the "Credentials"
Select Execute shell as the build step in the "Build Steps" section
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.
# 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"
Click Save to register the job
Execute the Job to Confirm Behavior
After defining a job, make sure if it works as expected.
Click the job name on the dashboard
Click Build Now to start the job
The build status can be seen in the left side of the page.
Click the top item in the "Builds" pane
The output can be seen by clicking the "Console Output".
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.