Prepare Test Data With Script
Precondition: Need the 3rd app Script Runner
What you will learn here
On this page, you will learn how to use script runner API to create the Data Test for clean up user
Overview
This script helps you create a user with sample data, to test User Data Cleanup usage
Please DO NOT use this script in your production
Installation Steps
Make sure you have ScriptRunner for Jira installed.
Download the script from this zip file.
Copy entire content to the 'scripts' folder located at
<your_jira_home>/scripts
.
This will ensure that the script is placed in the correct directory for use within ScriptRunner for Jira.
Configuration
Use in Script Runner Console: No configuration needed
Use via API:
In script runner plugin -> tab REST Endpoints
Click "Create REST Endpoint"
Enter an optional "Note" for your reference
Copy the path "com/mgm_tp/atlas/jira/udc/api/CreateTestUser.groovy" to File section
Click "Add"
Usage
ScriptRunner console:
To create a test user, run the following script from the script console:
package com.mgm_tp.atlas.jira.udc.helper
String[] options = []
def newUser = new TestDataGenerator(log).createTestUser(null, null, null)
newUser
This script generates a test user with a random name, email address, and full name
If you want to create a user with some extra data, add options to it:
package com.mgm_tp.atlas.jira.udc.helper
String[] options = [
"PROJECT_LEAD_PERMISSION",
"PROJECT_PERMISSION_ROLE",
"COMPONENT_LEAD_PERMISSION",
"PRIVATE_DASHBOARD",
"SHARED_DASHBOARD",
"PERMITTED_DASHBOARD",
"PRIVATE_FILTER",
"PERMITTED_FILTER",
"SHARED_FILTER",
"PERSONAL_SUBSCRIBED_FILTER",
"GROUP_SUBSCRIBED_FILTER",
"PRIVATE_AGILEBOARD",
"SHARED_AGILEBOARD",
"PERMITTED_AGILEBOARD",
"PERMISSION_SCHEME",
"NOTIFICATION_SCHEME",
"ISSUE_SECURITY_SCHEME",
"CF_USER_DEFAULT_CONTEXT",
"REMEMBER_ME_TOKEN",
"GROUPS",
"PERSONAL_ACCESS_TOKEN",
"AVATAR"
]
def prjKey = 'TEST'
def cfId = 'customfield_10301'
def newUser = new TestDataGenerator(log).createTestUser(options, prjKey, cfId)
newUser
You can also generate test data for a specific user
package com.mgm_tp.atlas.jira.udc.helper
import com.atlassian.jira.component.ComponentAccessor
String[] options = [
"PRIVATE_DASHBOARD",
"SHARED_DASHBOARD",
"PRIVATE_FILTER",
"SHARED_FILTER"
]
def user = ComponentAccessor.userManager.getUserByName('aaomzdtbx')
def updatedUser = new TestDataGenerator(log).updateUser(user, options, null, null)
Or create a user with your desired username, full name, email address,
and then generate data for the user.
package com.mgm_tp.atlas.jira.udc.helper
import com.atlassian.jira.component.ComponentAccessor
String[] options = [
"PRIVATE_DASHBOARD",
"SHARED_DASHBOARD",
"PRIVATE_FILTER",
"SHARED_FILTER"
]
def username = 'your-username'
def emailAddress = 'your-email@test.com'
def fullName = 'Your Full Name '
def user = new UserHelper(log).createUser(username, emailAddress, fullName)
def updatedUser = new TestDataGenerator(log).updateUser(user, options, null, null)
Options description
PROJECT_LEAD_PERMISSION
: Change your ‘TEST’ project lead to the created userPROJECT_PERMISSION_ROLE
: Add a project role to your ‘TEST’ project with value of the created userCOMPONENT_LEAD_PERMISSION
: Create a component lead in your ‘TEST’ project with value of the created userPRIVATE_DASHBOARD
: Create a private dashboard of the created userSHARED_DASHBOARD
: Create a shared dashboard of the created userPERMITTED_DASHBOARD
: Create a shared dashboard of the administrator, the created user will have the edit permission on this dashboardPRIVATE_FILTER
: Create a private filter of the created userSHARED_FILTER
: Create a shared filter of the created userPERMITTED_FILTER
: Create a shared filter of the administrator, the created user will have the edit permission on this dashboardPERSONAL_SUBSCRIBED_FILTER
: Create a shared filter of the administrator, the created user will have a personal filter subscription on this filterGROUP_SUBSCRIBED_FILTER
: Create a shared filter of the administrator, the created user will have a group filter subscription on this filterPRIVATE_AGILEBOARD
: Create a private agile board of the created userSHARED_AGILEBOARD
: Create a shared agile board of the created userPERMITTED_AGILEBOARD
: Create a shared agile board of the administrator, the created user is also the agile board administratorPERMISSION_SCHEME
: Create a permission scheme with value of the created userNOTIFICATION_SCHEME:
Create a notification scheme with value of the created userISSUE_SECURITY_SCHEME
: Create a issue security scheme with value of the created userCF_USER_DEFAULT_CONTEXT
: Create a context of your custom field with value of the created userAVATAR
: Create a default avatar for the created userGROUPS
: Add the created user to some random groupsPERSONAL_ACCESS_TOKEN
: Create a personal access tokenREMEMBER_ME_TOKEN
: Create a remember me token
ScriptRunner REST endpoints:
You can also create a test user via REST API but also you need basic authentication with username and password from an administrator in ‘jira-administrators’
Request
curl --request POST \
--url <jira_base_url>/rest/scriptrunner/latest/custom/createTestUser \
--data <your_request_body>
Example json body
{
"projectKey": "TEST",
"customFieldId": "customfield_10301",
"options": [
"PROJECT_LEAD_PERMISSION",
"PROJECT_PERMISSION_ROLE",
"COMPONENT_LEAD_PERMISSION",
"PRIVATE_DASHBOARD",
"SHARED_DASHBOARD",
"PERMITTED_DASHBOARD",
"PRIVATE_FILTER",
"PERMITTED_FILTER",
"SHARED_FILTER",
"PERSONAL_SUBSCRIBED_FILTER",
"GROUP_SUBSCRIBED_FILTER",
"PRIVATE_AGILEBOARD",
"SHARED_AGILEBOARD",
"PERMITTED_AGILEBOARD",
"PERMISSION_SCHEME",
"NOTIFICATION_SCHEME",
"ISSUE_SECURITY_SCHEME",
"CF_USER_DEFAULT_CONTEXT",
"REMEMBER_ME_TOKEN",
"GROUPS",
"PERSONAL_ACCESS_TOKEN",
"AVATAR"
]
}
User with NOT auto-generate user key
How to test user key NOT auto-generate:
Go to page: {URL}/secure/SiteDarkFeatures!default.jspa
Add Enable dark feature: com.atlassian.jira.user.dbIdBasedKeyGenerationStrategy.disabled
Add
Then create a new user.