Greetings thou Nacreous Natives

I am trying to use JIRA::Client to update a Jira issue, with partial success.

I have an issue of type "test subcase", which represents the use of a particular test case in a test plan. I am trying to change the custom field there called 'State', between these values: "Passed", "Failed", "In Progress", "Can't Test".

So, I managed to do the update with Perl: and looks (nominally) the same as when I manually do the change through a dialog called "Change Test Case State". However, some things that happened when I made the change manually are missing when I do it with Perl. It must be because there is something I do not know to do either with a different field, or with some aspect of the custom field (or both).

When I do the update manually, via the web client, the change propagates through the display of the state of the test subcase everywhere else, namely the test plan and the parent test case. When I do the update with my Perl script, the change shows up reliably in "Change Test Case State" dialog of the target test subcase, as well as in the history of that subcase, but there is no propagation of the new state to the display of the test subcase's state in other views. In those other views, the old value of 'state' persists (and disagrees with the value in the "Change Test Case State" dialog of the target test subcase.)

I also notice that the history entry is different between a manual change and a change using Perl. In a manual change from "In Progress" to "Can't Test", the History entry looks like this:

Tester, Intrepid made changes - Today 2:22 PM Status Open [ 1 ] Open [ 1 ] Test Case State In Progress { "state":"Can't Test","tp":"","tp +Start":"false"}

In a change from "In Progress" to "Can't Test", made by my Perl, the History entry looks like this:

Tester, Intrepid made changes - Today 2:38 PM Status Open [ 1 ] Open [ 1 ] Test Case State In Progress Can't Test

Here is the significant part of the code, that does the update:

$jira->progress_workflow_action_safely( $s_vetted_key, 'Change Test Ca +se State', {custom_fields => { 'customfield_10213' => { '0' => $s_tar +get_state}}}) ;

I tried to diagnose the problem by comparing a DataDumper of the issue retrieved by JIRA::Client::get_issue both after a manual update and one after a perl update, but there is no significant difference between them.

How can I do this correctly with PERL, so that it behaves more like the manual update, and lets my boss and teammates see that I have tested and recorded my results?

Thank you.

-sailortailorson

Here is all the code:

#!/usr/bin/perl -w # Sample Perl client accessing JIRA via SOAP using the CPAN # JIRA::Client module, to update a test case # use strict; use warnings; use Data::Dumper; use DateTime; use JIRA::Client; use Term::ReadKey; $|++; my $ra_states = { a => 'Passed', b =>'Failed', c =>'In Progress', d => + q{Can't Test}, q => 'quit'}; my $s_jira_url = 'https://jira.thankless_employer.com'; my $s_jirauser; my $s_passwd; print "\nCorp. login?:\t"; $s_jirauser = ReadLine(0); chomp $s_jirauser; ReadMode(2); print "\nCorp. passwd?:\t"; $s_passwd = ReadLine(0); chomp $s_passwd; ReadMode(0); print "\nThanks...\nNow connecting to $s_jira_url.\n"; my $jira = eval{JIRA::Client->new($s_jira_url, $s_jirauser, $s_passwd) +} or die("Could not log into $s_jira_url. Here's the problem: $@"); print "Connected.\n"; my $s_target_state = &choose_state($ra_states); my $command = "."; if ($s_target_state ne "quit") { print "\nEnter a liat of test subcase id's (or \"help\", if you ne +ed help, or \"state\" if you want to change the target state):\n\n"; } else { exit; } my $rh_test_subcases_to_update = {}; while( $command && $command !~ /^N(o|eg|yet|ein|icht)?|Q(uit)?/i ) { print "\n$s_target_state >> "; $command = <STDIN>; chop $command; if ( $command =~ /^help/i) { help(); } elsif ( $command =~ /\bstate\b/i) { $s_target_state = &choose_state($ra_states); } elsif ( $command && $command !~ /^N(o|eg|yet|ein|icht)?|Q(uit)?/i) { my $s_raw_id; my @a_raw_ids = split /(?:\s+|\s*?,\s*|\s*?;\s*)/, $command; foreach $s_raw_id (@a_raw_ids) { my $issue; my @a_errors; if ($s_raw_id !~ s/^((DS)?-)?(\d+)$/DS-$3/i) { push @a_errors, "$s_raw_id does not look like an issue + Key." } else { unless ($issue = eval{ $jira->getIssue($s_raw_id)}) { push @a_errors, "issue $s_raw_id could not be foun +d in $s_jira_url: $?"; } else { #unless ( $issue->{type} eq 'Test Subcase' ) #{ # push @a_errors, "issue $s_raw_id is not a 'Te +st Subcase', but a '" . $issue->{type} . "'."; #} unless ( $issue->{type} == 14 ) { push @a_errors, "issue $s_raw_id is not a '14' +, but a '" . $issue->{type} . "'."; } unless ( $issue->{assignee} eq $s_jirauser ) { push @a_errors, "issue $s_raw_id is not assign +ed to '$s_jirauser', but to '" . $issue->{assignee} . "'."; } } } if ( scalar @a_errors == 0 ) { if (not exists $rh_test_subcases_to_update->{$s_target +_state}) { $rh_test_subcases_to_update->{$s_target_state} = [ +]; } push @{$rh_test_subcases_to_update->{$s_target_state}} +, $s_raw_id; } else { print "\nI cannot set the state of $s_raw_id to $s_tar +get_state for the following " . (scalar @a_errors > 1 ? "reasons" : " +reason") . ":\n"; print "\n" . join "\n", @a_errors; print "\n"; } } print "Alright. Any more?\n"; } } print "\n$s_jirauser has ended the list.\n"; foreach $s_target_state (keys %{$rh_test_subcases_to_update} ) { foreach my $s_vetted_key ( @{$rh_test_subcases_to_update->{$s_targ +et_state}} ) { $jira->progress_workflow_action_safely( $s_vetted_key, 'Change + Test Case State', {custom_fields => { 'customfield_10213' => { '0' = +> $s_target_state}}}) ; print "\nChanged test subcase '$s_vetted_key' to '$s_target_st +ate'."; } } exit; sub choose_state { my $ra_states = shift; my ($raw_entry, $s_key, $s_state_choice); $s_key = ''; while( not (exists $ra_states->{$s_key}) ) { print "\nPlease choose a target state (by letter) from the followi +ng list:\n\n"; foreach $s_key (sort keys %{$ra_states}) { print sprintf "%s.\t%s\n", $s_key, $ra_states->{$s_key}; } print "\n"; $raw_entry = <STDIN>; chop $raw_entry; $raw_entry = lc($raw_entry); if ( $raw_entry =~ /^help/i) { help(); } elsif ( exists $ra_states->{$raw_entry} ) { $s_key = $raw_entry; $s_state_choice = $ra_states->{$s_key}; print "\n$s_jirauser chose $s_key: $s_state_choice...\n\n" +; } else { print "\nSorry, I did not understand your choice: $raw +_entry\n"; } } exit if $s_state_choice eq 'quit'; return $s_state_choice; } sub help { print "\nThis is a utility to do small bulk updates from the c +ommand line on jira test subcases.\n"; print "\nFirst, choose the state you want to change the curren +t group of test subcases to.\n"; print "\nThen, enter the test subcase IDs, either in one long +list, or pressing \"Enter\" after each one.\n"; print "\nYou can change state for assignment at any time, and +subsequently entered test subcase id's will be set to that state.\n"; print "\nTo prevent errors, this utility checks that the reque +sted issue exists, is a test subcase, and is assigned to you before"; print "\nit actually makes the change. If for some reason it f +inds a problem, it alerts you to the problem so you can correct the"; print "\nchoice."; print "\npress [Enter] to continue...\n"; my $nothing = <STDIN>; }

In reply to What's missing here when I use JIRA::Client to update a custom field in an issue? by sailortailorson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.