We are using Azure DevOps 2019 on-prem in our firm, and I would like to create an option box field in our Bug work item, and I want it to be a combo-box where the values are builds from all the build definitions under the project.
From checking the documentation of the system, I did not find any option to how to do it, and ether if it would be better to query the System through the API, or Query the DB.
I don't think there is a built-in feature like this.
What you can do, is to create a string field that takes the values from the gloabllist, in the globallist create in the first time a globallist with the project name, for example:
<GLOBALLIST name="MyProject-builds">
</GLOBALLIST>
Now you can use PowerShell to get the build definitions for this project, and update this globallist with the values:
Param(
[string]$collection = "http://tfs-server:8080/tfs/collection",
[string]$project = "MyProject",
[string]$filePath = "C:\Globallist.xml"
)
$url = "$collection/$project/_apis/build/definitions?api-version=4.0"
$builds = (Invoke-RestMethod -Uri $url -Method Get -UseDefaultCredentials -ContentType application/json).value.name
witadmin exportgloballist /collection:$collection /f:$filePath
[xml]$gloabllist = Get-Content $filePath
$gloabllist.GLOBALLISTS.GLOBALLIST.Where({ $_.name -eq "$project-builds" }).LISTITEM | %{ $_.ParentNode.RemoveChild($_) | Out-Null }
$node = $gloabllist.GLOBALLISTS.GLOBALLIST.Where({ $_.name -eq "$project-builds" })
$builds.ForEach({
$child = $gloabllist.CreateElement("LISTITEM")
$att = $gloabllist.CreateAttribute("value")
$child.Attributes.Append($att)
$child.value = "$_"
$node.AppendChild($child)
})
$gloabllist.Save($filePath)
witadmin importgloballist /collection:$collection /f:$filePath
You can set a scheduled build that tun this script each day to be updated all the time.
You can also improve the script to get all the projects, itreate them, get the build definitions names and update the globallist file.
Related
I have a jenkins pipeline which gives the user a list of keys from Consul, the user should choose one option (using active choice parameter), I need the pipeline to dynamically generate the list of "sub keys" (depends on the user first choice, for example: key/path/${user_choice} ) and let the user to choose a sub key
my current code his:
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = ['/bin/bash', '-c', 'consul kv get -keys --http-addr=X key/path/ | awk -F / \'{print $(NF-1)}\''].execute()
proc.consumeProcessOutput(sout, serr)
proc.waitFor()
return sout.tokenize()
It works fine till now, but "active choice reactive parameter" is not acting dynamically and refuse to relate to the user's first choice. I haven't found any other useful plugin
Any help?
thanks :)
From what I know you can't have an interactive command prompt in Jenkins. However, you can use the input step to get feedback and use it throughout the pipeline like so:
def keys = sh(script: 'consul kv get -keys --http-addr=X key/path/ | awk -F / \'{print $(NF-1)}\'', returnStdout: true).trim().tokenize('\n')
def choice = input message: 'Please choose a sub-key', parameters: [choice(choices: keys, description: '', name: 'Subkeys')]
println "You chose $choice"
Our team is quite used to the build quality value in TFS 2015 and earlier XAML builds. This is not possible with the new Build & Release, but we can add tags to a build. However, they are not shown in the list of builds, we can only filter by tags in the build definition history (which shows a list of builds). Is there anyway to configure this to show tags for builds? Or any other way to show the tags in a list of builds?
We can use REST API to get these values back, is there a way to modify the web pages or add our own?
Note - we did NOT install SharePoint so we can't use that.
There isn't a way to configure to show tags for builds, it's not supported.
There is a User Voice here to suggest the feature, you can go and vote it up to achieve it in future.
As a workaround, you can list the tags with build tags REST API, then filter the builds by tags just as you did.
Another way is retrieving the build list with tags using REST API.
For example, you can use below PowerShell script to get the build list with tags and export the build list to a .csv file.
$Collection = "http://server:8080/tfs/DefaultCollection"
$teamproject = "ProjectName"
$baseUrl = "$Collection/$teamproject/_apis/build/builds?api-version=2.0"
$builds = (Invoke-RestMethod -Uri $baseUrl -Method Get -UseDefaultCredential).value
$BuildResults = #()
foreach($build in $builds){
$customObject = new-object PSObject -property #{
"BuildDefinition" = $build.definition.name
"BuildId" = $build.id
"BuildNumber" = $build.buildNumber
"status" = $build.status
"result" = $build.result
"finishTime" = $build.finishTime
"sourceBranch" = $build.sourceBranch
"sourceVersion" = $build.sourceVersion
"tags" = #($build.tags -join ',')|Select-Object
"RequestedFor" = $build.requestedFor.displayName
}
$BuildResults += $customObject
}
$BuildResults | Select `
BuildDefinition,
BuildId,
BuildNumber,
status,
result,
finishTime,
sourceBranch,
sourceVersion,
tags,
RequestedFor|export-csv -Path E:\user\$teamproject-Build.csv -NoTypeInformation
I want to be able to have multiple forms of the same parameter like so:
param(
[string]$p or $path = "C:\",
[string]$f or $filter = "*.txt",
[switch]$o or $overwrite
)
but I'm not sure how to do this. Most times, you would only be able to choose one (e.g. only $p or only $path). Is it possible to use multiple names for the same variable/parameter?
Like this:
param(
[Alias('p')]
[string]$path = "C:\",
[Alias('f')]
[string]$filter = "*.txt",
[Alias('o')]
[switch]$overwrite
)
Note you can have multiple aliases too: [Alias('p','thepath')]
PowerShell partial parameter name matching may be what your looking for.
# test.ps1
param($path)
write-host $path
Calling .\test.ps1 with either .\test.ps1 -path "c:\windows" or .\test.ps1 -p "c:\windows" will both match, and populate, the $path parameter.
I needed to change a work item field from PlainText -> String.
As I could not change the type on the Work Item, creating a new field and updating it's value from the other field is my approach.
I have tried the "Bulk Edit Selected Work Items.." from TFS/Web but I'm not sure if you may reference another field value in that template.
How may I set [Work Item].[FieldNew].Value = [Work Item].[FieldOriginal].Value ??
Is this even possible without having to use the TFD API?
The reason why I need to change the item field type from PlainText to String is that I want to have a query with a column operator to test if the field has value or not.
For a plainText field the only allowed operator is Contains/Does Not Contain. May I override this to allow a ">" ?
KMoraz's solution does not work for me either, because the HTML field becomes read-only when exported to Excel. Therefore, I used a Powershell script to copy the value of one field into another (just replace the "$wiFieldNewValue" variable with the source field you are copying)
Code reference: Bulk update TFS work items using Powershell
Link to code
Embedded code:
#This script sets a specific field to a specified value for all work items in a specific project
Function LoadTfsAssemblies() {
Add-Type –AssemblyName "Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Add-Type -AssemblyName "Microsoft.TeamFoundation.WorkItemTracking.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
}
##### SETTINGS
#The TFS Team Project Collection to connect to
$tfsUri = "http://tfsserver:8080/tfs/DefaultCollection"
#The TFS Team Project from which to select the work items
$tfsProject = "Test Project"
#The work item type of the work items to update
$wiType = "Test Case"
#The reference name of the field to update
$wiFieldRefName = "Microsoft.VSTS.Common.Priority"
#The value to set the field to
$wiFieldNewValue = "1"
##### END SETTINGS
LoadTfsAssemblies
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsUri)
$tfs.EnsureAuthenticated()
if($tfs.HasAuthenticated)
{
Write-Output "Successfully authenticated to TFS server [$tfsUri]"
$workItemStore = $tfs.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
$query = "SELECT [System.Id], [System.Title] FROM WorkItems WHERE [System.TeamProject] = '{0}' AND [System.WorkItemType] = '{1}'" -f $tfsProject, $wiType
Write-Output("Using query [$query]")
$workItems = $workItemStore.Query($query)
Write-Output("Going to update [{0}] work items" -f $workItems.Count)
$successCount = 0
$failureCount = 0
ForEach($wi in $workItems) {
Write-Output("Updating work item [{0}]" -f $wi.Title)
try {
$wi.Open()
$wi.Fields[$wiFieldRefName].Value = $wiFieldNewValue
Write-Output("Set field [{0}] to [{1}]" -f $wiFieldRefName, $wiFieldNewValue)
$validationMessages = $wi.Validate()
if($wi.IsValid() -eq $true)
{
$wi.Save()
Write-Output("Successfully updated work item [{0}]" -f $wi.Title)
$successCount++
} else {
Write-Error("Work item is not valid!")
ForEach($validationMessage in $validationMessages)
{
Write-Error("Error: {0}" -f $validationMessage)
}
$failureCount++
}
} catch {
Write-Error("Couldn't set field [{0}] to [{1}] for work item [{2}]" -f $wiFieldRefName,$wiFieldNewValue,$wi.Title)
Write-Error $_
$failureCount++
}
}
Write-Output("Finished!")
Write-Output("Successfully updated: {0}" -f $successCount)
Write-Output("Failed to update: {0}" -f $failureCount)
} else {
Write-Error("Couldn't authenticate to TFS server [$tfsUri]")
}
I'ts possible via Excel.
Create a query with both old and new field columns visible.
Export the query to Excel.
Copy and paste the data from old field column to the new field.
In Excel, from the Team menu click Publish to update the changes in TFS.
Sorry if SO is not the best place, but I have time-tracking enabled in JIRA and want to be able to generate a time-report for each user over a given date range. The only time-tracking report option I have is very limited and doesn't do what I want, is it possible through standard functionality or a free plugin perhaps?
You might want to check out Tempo Plugin for JIRA timetracking. It offers timesheets, reports and gadgets on user, team, project, and customer levels.
how about this one:
https://plugins.atlassian.com/plugin/details/294
If you don't want to pay a lot of money for a simple action like getting a summary of time per user.
I found this flow useful:
Create a filter that you like to measure (I measure time only by sub tasks)
Export it to excel
Copy and paste it into a google docs spreadsheet
In google docs you have an option to create a Pivot Table, so just create one that the rows are the assignees and the values are the time
You can also create a calculated column to get the time in hours (just divide it by 3600)
Hope it helps
Using the Better Excel Plugin you can take advantage of all reporting features in Microsoft Excel.
This plugin exports any sort of JIRA data (including issue fields and worklogs) to custom Excel templates. The templates can use filtering to the date range, and can display your report in an Excel pivot table. If you need further dimensions (like additional grouping by project, by component, by week, by month, etc.), these are super simple to add. You can also visualize the output in a pivot chart.
Tip: there is a default template included in the plugin, called worklog-report.xlsx, which can be used as is, or as starting point for further customization. It looks like this (there is a time-by-project pivot chart in the first worksheet, but I don't have a screenshot about that):
After the template is created, you can merge that with the most current JIRA data any time by a single click, or even generate it and email it to you automatically.
Disclaimer: I'm a developer working on this paid add-on.
You can easily do it with Everhour add-on for JIRA. It allows receiving a comprehensive report for each user over a given date range. And you are absolutely free to build any other layout of your reports and add as many data columns as you need.
Jira Sample Report - Everhour
If you're on Windows you can run the following powershell script to extract the data to CSV file.
## Instructions ##
Open Powershell ISE (It's installed to all windows 7 and later PCs)
Create a new PowerShell script (ctrl+n)
Paste the text from the following code block into the new file
##################################################################
# Variables
##################################################################
$username = "myname#asdf.com"
$password = Read-host "What's your Jira password?" -AsSecureString
#$password = ""
$jiraDomain = "asdf.atlassian.net"
$projectKey = "ABC"
$startDate = [datetime]::ParseExact('2017-05-08', 'yyyy-MM-dd', $null)
$endDate = Get-Date
#Get-Date = today
$csvFileName =c:\temp\Worklog.csv
##################################################################
# Functions
##################################################################
function get-jiraData {
param( [string]$restRequest)
Invoke-RestMethod -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri $restRequest
}
function get-issues {
param( [string]$projectName)
$uri = "https://${jiraDomain}/rest/api/2/search?jql=project=${projectName}"
$issuesPage = get-jiraData -RestRequest $uri
#write first batch of issues
$issuesPage.issues
#do next batches
do {
$startAt = $issuesPage.maxResults + 1
$uri = "https://${jiraDomain}/rest/api/2/search?jql=project=${projectName}&startAt=$startAt"
$issuesPage = get-jiraData -RestRequest $uri
#write next batch of issues
$issuesPage.issues
} while (($issuesPage.startAt + $issuesPage.maxResults) -lt $issuesPage.total)
}
filter convert-worklog {
$worklog = New-Object System.Object
$worklog | Add-Member –type NoteProperty –Name Person –Value $_.author.name
$worklog | Add-Member –type NoteProperty –Name IssueKey –Value $key
$startDate = [datetime]::ParseExact($_.started.Substring(0,16), 'yyyy-MM-ddTHH:mm', $null)
$worklog | Add-Member –type NoteProperty –Name DateLogged –Value $startDate
$TimeMinutes = $_.timeSpentSeconds / 60
$worklog | Add-Member –type NoteProperty –Name TimeSpent –Value $TimeMinutes
$worklog | Add-Member –type NoteProperty –Name Comment –Value $_.comment
$worklog
}
filter extract-worklogs {
#$key = "WL-22"
$key = $_.key
$uri = "https://${jiraDomain}/rest/api/2/issue/${key}/worklog"
$worklogsPage = get-jiraData -RestRequest $uri
#write first batch of worklogs
$worklogsPage.worklogs | convert-worklog
#Check for another batch of worklogs
do {
$startAt = $worklogsPage.maxResults + 1
$uri = "https://${jiraDomain}/rest/api/2/issue/${key}/worklog?startAt=$startAt"
$worklogsPage = get-jiraData -RestRequest $uri
#write next batch of worklogs
$worklogsPage.worklogs | convert-worklog
} while (($worklogsPage.startAt + $worklogsPage.maxResults) -lt $worklogsPage.total)
}
##################################################################
# Execution
##################################################################
#Setup Authentication variable
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
#This grabs all the worklogs for a project, then filters them by
$WorkLogs = get-issues -projectName $projectKey | extract-worklogs | ?{ $_.DateLogged -gt $startDate -and $_.DateLogged -lt $endDate } | sort DateLogged
$WorkLogs | export-csv $csvFileName -NoTypeInformation
Modify the variables at the start of the file
Save as a powershell script somewhere on your PC
Run the script by double clicking it