Skip to main content
Skip table of contents

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

  1. Make sure you have ScriptRunner for Jira installed.

  2. Download the script from this zip file.

udc-script.zip

  1. 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

  1. Use in Script Runner Console: No configuration needed

  2. Use via API:

    1. In script runner plugin -> tab REST Endpoints

    2. Click "Create REST Endpoint"

    3. Enter an optional "Note" for your reference

    4. Copy the path "com/mgm_tp/atlas/jira/udc/api/CreateTestUser.groovy" to File section

    5. Click "Add"

Usage

ScriptRunner console:

To create a test user, run the following script from the script console:

GROOVY
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:

GROOVY
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

CODE
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.

CODE
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 user

  • PROJECT_PERMISSION_ROLE : Add a project role to your ‘TEST’ project with value of the created user

  • COMPONENT_LEAD_PERMISSION : Create a component lead in your ‘TEST’ project with value of the created user

  • PRIVATE_DASHBOARD: Create a private dashboard of the created user

  • SHARED_DASHBOARD : Create a shared dashboard of the created user

  • PERMITTED_DASHBOARD : Create a shared dashboard of the administrator, the created user will have the edit permission on this dashboard

  • PRIVATE_FILTER : Create a private filter of the created user

  • SHARED_FILTER : Create a shared filter of the created user

  • PERMITTED_FILTER : Create a shared filter of the administrator, the created user will have the edit permission on this dashboard

  • PERSONAL_SUBSCRIBED_FILTER : Create a shared filter of the administrator, the created user will have a personal filter subscription on this filter

  • GROUP_SUBSCRIBED_FILTER : Create a shared filter of the administrator, the created user will have a group filter subscription on this filter

  • PRIVATE_AGILEBOARD: Create a private agile board of the created user

  • SHARED_AGILEBOARD : Create a shared agile board of the created user

  • PERMITTED_AGILEBOARD: Create a shared agile board of the administrator, the created user is also the agile board administrator

  • PERMISSION_SCHEME: Create a permission scheme with value of the created user

  • NOTIFICATION_SCHEME: Create a notification scheme with value of the created user

  • ISSUE_SECURITY_SCHEME: Create a issue security scheme with value of the created user

  • CF_USER_DEFAULT_CONTEXT: Create a context of your custom field with value of the created user

  • AVATAR: Create a default avatar for the created user

  • GROUPS: Add the created user to some random groups

  • PERSONAL_ACCESS_TOKEN: Create a personal access token

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

CODE
curl --request POST \
--url <jira_base_url>/rest/scriptrunner/latest/custom/createTestUser \
--data <your_request_body>

Example json body

CODE
{
  "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:

  1. Go to page: {URL}/secure/SiteDarkFeatures!default.jspa

  2. Add Enable dark feature: com.atlassian.jira.user.dbIdBasedKeyGenerationStrategy.disabled

  3. Add

Then create a new user.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.