AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
325 stars 131 forks source link

Set-JiraConfigServer see's path to config file as an xml object, rather than a string #169

Open JoeJe1993 opened 7 years ago

JoeJe1993 commented 7 years ago

When trying to use Set-JiraConfigServer to create the config file, the following error is returned.

NOTE: I'm using a custom module to catch exception messages. (Last two Debug messages that have [ERROR] and [FAIL] in them)

Import-Module C:\Users\user\Desktop\SomeModule\SomeModule.psm1 -Force
Import-Module JiraPS -Force

$JiraSettings = @{

    Project     = "DOC"
    Reporter    = "email@domain.com"
    Credentials = (New-Object System.Management.Automation.PSCredential("user",((ConvertTo-SecureString -AsPlainText -Force "password"))))
    Server      = "https://domain.tld/jira"

}

$LogFolder = "C:\Users\user\desktop\JiraTestLog"

function RaiseTicket([string]   $Title,
                     [string]   $Message,
                     [Hashtable]$JiraConfig) {

    try {

        [net.servicepointmanager]::securityprotocol = [net.securityprotocoltype]::Tls12
        Set-JiraConfigServer -Server $JiraConfig.Server

        $Ticket = New-JiraIssue -Project     $JiraConfig.Project `
                                -IssueType   Incident `
                                -Summary     ("Pull Transfer Script: {0} - {1}" -f $ConfigFile.Settings.ScriptSettings.ClientName,$Title) `
                                -Description $Message `
                                -Reporter    $JiraConfig.Reporter `
                                -Credential  $JiraConfig.Credentials `
                                -ErrorAction Stop 

        Log -CallingFrom $MyInvocation.MyCommand -Status PASS -Message ("Created Ticket: {0}. Ticket Number: {1}" -f $Title,$Ticket.Key) -LogFolder $LogFolder

    } catch {

        Log -CallingFrom $MyInvocation.MyCommand -Status FAIL  -Message ("Unable to create ticket: {0}" -f $Title) -LogFolder $LogFolder
        Log -CallingFrom $MyInvocation.MyCommand -Status ERROR -Message $_.Exception.Message                       -LogFolder $LogFolder

    }

}

RaiseTicket "JOE TEST TICKET" "Lorem ipsum dolor sit amet" $JiraSettings

image

lipkau commented 7 years ago

First things first

Your script does work with one exception: -Reporter must be the username and not the email address

Appart from that, it works perfectly: image

Now to the xml problem

You are currently saving the xml file to the root of the module path. As I do not know where the file is being saved, I would guess:

  1. is the module installed as admin? if so, the currentuser might not have the permissions to create the file
  2. is the module on a network resource? if so, I believe this is untested

The current version of the module has all verbose or debug messages in the function commented ou - you can uncomment the debug messages in Get-JiraConfigServer and try to trace the cause for this problem.

JoeJe1993 commented 7 years ago

Module is not on network resource. Module was installed as admin.

lipkau commented 7 years ago

Must the module be installed as admin? Can you add the line Install-Module JiraPS -scope currentuser in the script?

JoeJe1993 commented 7 years ago

Tried, makes no difference.

JoeJe1993 commented 7 years ago

FOUND THE PROBLEM: I had a Variable called $ConfigFile set as an XML object in my script. This interfered with JiraPS and caused the issue I was having.

This bug also exists in PSJira.

lipkau commented 7 years ago

That's a weird thing to happen... Get-JiraConfigServer only references $ConfigFile without a prefix, which should only use the variable in the scope of the function; not fetching the value from $global:ConfigFile.

Well. This should be considered in #45