File: createWorkitemsInBulk.ps1

package info (click to toggle)
azure-devops-cli-extension 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,384 kB
  • sloc: python: 160,782; xml: 198; makefile: 56; sh: 51
file content (62 lines) | stat: -rw-r--r-- 2,176 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#---------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

param(
[string]$workitem_titles,
[string]$wit_template
)

Write-Host("Sample Usage -")
Write-Host("createWorkitemsinBulk.ps1 -workitem_titles ./my_wit_titles -wit_template ./my_wit_template")

<# 
Sample Wit Template :

organization=https://dev.azure.com/baggaatul24
project=testproject
workitem_type=Task
assignedto=
area=
iteration=
#>

if (!$wit_template)
{
    Write-Host("Template not provided will ask for default params interactively. Alternatively create a wit template and pass it to the script.")
    $organization = Read-host("Organization URL: ")
    $project = Read-host("Project Name: ")
    $workitem_type = Read-host("Workitem Type: ")
}
else{
    foreach($line in Get-Content $wit_template) {
    #    Write-Host($line)
        $arr = $line.split('=')
        $x = "$" + $arr[0]
        $y = """" + $arr[1] + """"
        if($y){
            Invoke-Expression("$x = $y")
        }
    }

    Write-Host("Creating a task with organization - " + $organization)
    Write-Host("Creating a task with project - " + $project)
    Write-Host("Creating a task with assigned to - " + $assignedto)
}

if (!$workitem_titles)
{
    Write-Host("No file for workitem titles. Will run in interactive mode to create workitems.")
    while(1) {
        $title = Read-Host("Enter workitem title: ")
        $command_string = "az boards work-item create --org $organization --project $project --title ""$title"" --type $workitem_type" # --assigned-to $assignedto #Doesnot seem to work
        Invoke-Expression($command_string) 
    }
}
else {
    foreach($line in Get-Content $workitem_titles) {
        $command_string = "az boards work-item create --org $organization --project $project --title ""$line"" --type $workitem_type" # --assigned-to $assignedto #Doesnot seem to work
        Invoke-Expression($command_string) 
    }
}