Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Connect, share and learn on the different examples!

Hello Community,

My name is Gonchik Tsymzhitov!  I am Atlassian User Group Leader in Saint-Petersburg and also Atlassian administrator. Each of the Atlassian administrators involved into customization and deep configuration of Jira. And for anyone it is not secret that the customization cycle goes through several stages, such as:

  1. Finding a solution through the built-in capabilities of the product, for example, using additional workflow settings (property, post-function, validators, conditions and triggers)
  2. Polishing of small defects, users' desires through JS scripts, (for example, JS Includer with small tricks for painting statuses or in Announce banner)
  3. If you need a small functionality and also we have resources for the support or maintenance code, hence we are looking for open source plugins on github.com, bitbucket.org.
  4. If we need for the big or specific functionality, then look for all the known marketplace.atlassian.com
  5. This is when the paid plug-in needs to be polished with a little functionality, and the plans of the plug-ins do not start in the near future, then we begin to wrap using different tools (Scriptrunner, Groovioli, Groovy Amigo, JS includer, python, SIL), depending on the tasks.

And always the last point in solving problems is interesting. Therefore, I would like to share my crutches with pleasure, maybe a plug-in vendor will add a little functionality.

So, my experience will be on the example of using the plug-in TestFlo, formerly SuiTest. This plugin supported by Devinity (formerly InTENSO) and provide test management functionality. 

In this article I'll tell you about transitions to Pass, Fail. Because the remaining steps are customized function from the built-in functionality Jira Software or plug-in functionality.

So, let's go.

At one point, I needed a validator in TestCase's workflow so that when I switched to the “Pass” status, I checked the presence of the “Pass” status for each step in the dynamic custom field “Steps”.

For ease of understanding, I attached a small workflow.

workflow.PNG

 Validator for Pass status transition: 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.opensymphony.workflow.InvalidInputException
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.itiviti.jira.scripts.groovy.Steps")

/* Initialize variables */
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def emptySteps = false
def inProgressSteps = false
def failedSteps = false
def failedStatusConfig = "<div class=\"visible-status-label\" style=\"background-color:#CC3300\">Failed</div>"
def emptyStatusConfig = "<div class=\"visible-status-label\" style=\"background-color:#FFFFFF\"> </div>"
def inProgressStatusConfig = "<div class=\"visible-status-label\" style=\"background-color:#6693B0\">In Progress</div>"
def passedStatusConfig = "<div class=\"visible-status-label\" style=\"background-color:#51A825\">Passed</div>"

String rawHtml = cfSteps.getViewHtml(ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(cfSteps), null, issue).toString()
emptySteps = rawHtml.contains(emptyStatusConfig)
log.debug('Found the empty steps ' + emptySteps)
if (emptySteps) {
    throw new InvalidInputException("fixVersions", "Please, fill for all Step statuses! Some steps are empty.")
}
inProgressSteps = rawHtml.contains(inProgressStatusConfig)
log.debug('Found the In progress steps ' + inProgressSteps)
if (inProgressSteps) {
    throw new InvalidInputException("fixVersions", "Please, fill for all Step statuses correctly! Some steps have  'In progress' status.")
}
failedSteps = rawHtml.contains(failedStatusConfig)

log.debug('Found the Failed steps ' + failedSteps)
if (failedSteps) {
    throw new InvalidInputException("fixVersions", "Please, fill for all Step statuses correctly! Some steps has been failed.")
}

log.debug('=== empty info ===')

This validator includes error messages related steps statuses under the Fix version/s.

Also, the validator needed to re-enter the “Fail” status, because it is necessary to avoid the situation when accidentally transferred to the status in “Fail”.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.opensymphony.workflow.InvalidInputException
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.itiviti.jira.scripts.groovy.Steps")
/* Initialize variables */
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def emptySteps = false
def inProgressSteps = false
def failedSteps = false
def failedStatusConfig = "<div class=\"visible-status-label\" style=\"background-color:#CC3300\">Failed</div>"
def emptyStatusConfig = "<div class=\"visible-status-label\" style=\"background-color:#FFFFFF\"> </div>"
def inProgressStatusConfig = "<div class=\"visible-status-label\" style=\"background-color:#6693B0\">In Progress</div>"
def passedStatusConfig = "<div class=\"visible-status-label\" style=\"background-color:#51A825\">Passed</div>"
CustomField cfSteps = customFieldManager.getCustomFieldObjectByName("Steps")
String rawHtml = cfSteps.getViewHtml(ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(cfSteps), null, issue).toString()

emptySteps = rawHtml.contains(emptyStatusConfig)
log.debug('Found the empty steps ' + emptySteps)
if (emptySteps) {
    throw new InvalidInputException("fixVersions", "Please, fill for all Step statuses! Some steps are empty.")
}

inProgressSteps = rawHtml.contains(inProgressStatusConfig)

log.debug('Found the In progress steps ' + inProgressSteps)

if (inProgressSteps) {
    throw new InvalidInputException("fixVersions", "Please, fill for all Step statuses correctly! Some steps have  'In progress' status.")
}

failedSteps = rawHtml.contains(failedStatusConfig)
log.debug('Found the Failed steps ' + failedSteps)
if (!failedSteps) {
    throw new InvalidInputException("fixVersions", "Sorry, one or more steps should be in status Failed")
}

Well, the next step is the presence of a “Defect” (it is issue link type with inward and outward link name “defect” for determine results from testing process).   Therefore the test case with the status “Fail” should have the defect link type to Bug. I made this validator as an inline mode in Scriptrunner like this:

image.png

Related code is :

def linkCnt = 0
def request = webwork.action.ActionContext.getRequest()
if (request) {
    // check for new defect link throw screen
    def linktype = request.getParameter('issuelinks-linktype')
    def linkedIssue = request.getParameter('issuelinks-issues')
    if (linktype == 'defect' && linkedIssue) {
        linkCnt = 1
    }
}
// check for existing defects link
if ( issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Defect') ) {linkCnt = 1}
if ( issueLinkManager.getInwardLinks(issue.getId())*.issueLinkType.name.contains('Defect') ) {linkCnt = 1}
// Transition requires one, and only one, defects link

(linkCnt==1)

 

The conclusion of this article is if everyone will share the crafts we can develop the community and themselves. Since my code is not perfect, as I was tied to a static color parameter steps, but unfortunately mean places without access to the Java API I went that way. And that's why I would really like to see vendors offering solutions and also correct solution.

Thank you Atlassian for the platform for the Online Community and good thesis – “Connect, Share and Learn”!

 

P.S. It will be nice if someone review my code and provide use cases.

 

Thanks

Cheers,

Gonchik Tsymzhitov

 

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events