Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Friday, September 8, 2017

TFS 2015 Build ile Çağrılan PowerShell'e Parametre Değeri Göndermek



    TFS Build ile çağrılan PowerShell'e  parametre göndermek için yapılması gereken işlemler aşağıdaki gibidir.

    Build Tanımları

             1.   Build tanımına PowerShell adımı eklenir.



             2. Repository tabına gidilip 'Mappings' ayarları yapılır


             3. Variables tabına gidilip, scripte kullanılan parametreler tanımlanır.


            4. Build tabında Arguments alanına scritpe gönderilecek olan  parametreler yazılır.



        Powershell'de  parametre tanımlaması


        param(
   
                              [Parameter(Mandatory=$true)]
                              [string]$UserName,
   
                              [Parameter(Mandatory=$true)]
                              [string]$Password
             )

TFS Rest Api ile Test Case Oluşturmak



    Yaptığım iş gereği var olan bir Test Case değerini okuyup tekrar oluşturmam gerekti.
 
     $response =  Invoke-RestMethod -Uri "http://tfsaddress/collectionname/_apis/wit/workItems/1"

     if($response.fields.'System.WorkItemType' -eq "Test Case")
     {
     
       $areaPath        = $response.fields.'System.AreaPath'.Replace("\","\\")
       $teamProject     = $response.fields.'System.TeamProject'
       $iterationPath   = $currentIteration
       $workItemType    = $response.fields.'System.WorkItemType'
       $title           = $response.fields.'System.Title'
       $priority        = $response.fields.'Microsoft.VSTS.Common.Priority'
       $automationStatus= $response.fields.'Microsoft.VSTS.TCM.AutomationStatus'
       $steps           = $response.fields.'Microsoft.VSTS.TCM.Steps'.Replace('"',"'")
       $assignToUser    = $assignToUser.Replace("\","\\")

       $json = @"
       [
        {
             "op": "add",
             "path": "/fields/System.Title",
             "value":"$title"
        },

        {
             "op": "add",
             "path": "/fields/System.TeamProject",
             "value":"$teamProject"
        },
       
        {
            "op" : "add",
            "path": "/fields/System.AreaPath",
            "value": "$areaPath"
        },
       
        {
            "op" : "add",
            "path": "/fields/System.WorkItemType",
            "value": "$workItemType"
        },
         
        {
           "op" : "add",
           "path": "/fields/System.IterationPath",
           "value": "$iterationPath"
        },  
     
        {
           "op":"add",
           "path":"/fields/System.State",
           "value":"Design"
        },

        {
           "op" : "add",
           "path": "/fields/Microsoft.VSTS.Common.Priority",
           "value": "$priority"
        },

        {
            "op" : "add",
            "path": "/fields/Microsoft.VSTS.TCM.AutomationStatus",
            "value": "$automationStatus"
        },

        {
           "op" : "add",
           "path": "/fields/Microsoft.VSTS.TCM.Steps",
           "value": "$steps"

        },

        {
           "op" : "add",
           "path": "/fields/System.AssignedTo",
           "value": "$assignToUser"

        },

        ]"
"@

}

   
$result = Invoke-RestMethod  -Uri "http://tfsaddress/collectionname/_apis/wit/workitems/`$Test%20Case?api-version=1.0"
                             -Credential $mycreds
                             -Method Patch
                             -Body  $json
                             -ContentType "application/json-patch+json"




Wednesday, August 16, 2017

PowerShell Invoke-RestMethod Türkçe Karakter Problemi



PowerShell üzerinden rest method invoke etmeye çalışırken, post ettiğim parametre değerlerinde Türkçe karakterler problemi yaşandı. Gönderdiğim json parametresini  UTF8 encoding ile gönderince problem düzeldi.


$secpasswd = ConvertTo-SecureString "mypassword" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("myuser", $secpasswd)

$jsonParam = "{""name"":""Özlem"",""surname"":""Arslan""}"

Invoke-RestMethod  -Uri $createUri -Credential $mycreds -Method "Post" -Body  ([System.Text.Encoding]::UTF8.GetBytes($jsonParam))  -ContentType "application/json"

Ürdün

  Çok hızlı bir şekilde karar alıp, harekete geçtiğim bir gezi oldu Ürdün. Nitekim bir pazar günü arkadaşım Firuze ile konuşup, pazartesi...