I want to pick all workitem from TFS using .wiq file,But getting errors while doing so - powershell-ise

Below is piece of code.
{
# Load required assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
# Wiq Path
$WiqPath = $PSScriptRoot+"\"+$wiqFile
try
{
# Get TFS server and query from WIQ file
[xml]$WiqlXML = Get-Content $WiqPath
[String]$TFSservername = $WiqlXML | % {$_.WorkItemQuery.TeamFoundationServer}
[String]$queryString = $WiqlXML | % {$_.WorkItemQuery.Wiql}
Write-Host "TFS path is: " $TFSservername "`r`n"
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TFSservername)
# Get workitem collection from TFS Project
$ws = $teamProjectCollection.GetService([type][Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
# If user has passed explicitly Ids
if($workItemIds)
{
$workIs = $workItemIds.Split(',')
# collection of workitem objects
$wis = #()
foreach($wi in $workIs)
{
$wis += $ws.getworkitem($wi)
}
}
# If user hasn't passed Ids, taking Workitem Ids from wiqFile
else
{
$wis = $ws.Query($queryString)
}
# Pass Default credentials. Make sure whoever is running script, have access on TFS project
[Net.WebClient] $request = New-Object Net.WebClient
$request.UseDefaultCredentials = $true
}
Exception details :-
Caught an exception:
Exception Type: System.Management.Automation.MethodInvocationException
Exception Message: Exception calling "Query" with "1" argument(s): "The specified variable does not exist. The error is caused by «#project»."

I had the same issue. As a workaround, I replaced the #project field with the project name from Microsoft.TeamFoundation.WorkItemTracking.Client.Project-object. In your case you should also add the project name to WIQ file. Otherwise if the project name is constant, you could just replace it with your project name:
$projectName = "MyTfsProject"
$queryString = $queryString -replace "#project", ("'{0}'" -f $projectName)

Related

How to properly use bazel transitions for multiarch build

I'm trying to define a bazel rule that will build 2 different cc_binaries for 2 different platforms with just 1 bazel build invocation. I'm struggling with how to define the transition properly and attach it.
I would like ultimately to be able to do something like:
cc_binary(
name = "binary_platform_a"
...
)
cc_binary(
name = "binary_platform_b"
...
)
my_custom_multi_arch_rule(
name = "multiarch_build",
binary_a = ":binary_platform_a",
binary_b = ":binary_platform_b",
...
)
I have deduced from bazel documents: [https://bazel.build/rules/config#user-defined-transitions] that I need to do something like the following in a defs.bzl:
def _impl(settings, attr):
_ignore = (settings, attr)
return {
"Platform A": {"//command_line_option:platform": "platform_a"},
"Platform B": {"//command_line_option:platform": "platform_b"},
}
multi_arch_transition = transition(
implementation = _impl,
inputs = [],
outputs = ["//command_line_option:platform"]
)
def _rule_impl(ctx):
# How to implement this?
my_custom_multi_arch_rule = rule(
implementation = _rule_impl,
attrs = {
"binary_a": attr.label(cfg = multi_arch_transition)
"binary_b": attr.label(cfg = multi_arch_transition)
...
})
The best-case final scenario would be able to issue:
bazel build //path/to/my:multiarch_build
and it successfully builds my 2 separate binaries for their respective platforms.
Use ctx.split_attr.<attr name>[<transition key>] to get the configured Target object representing a particular arch configuration of a binary.
def _rule_impl(ctx):
binary_a_platform_a = ctx.split_attr.binary_a["Platform A"]
binary_a_platform_b = ctx.split_attr.binary_b["Platform B"]
# ...
return [DefaultInfo(files = depset([binary_a_platform_a, binary_b_platform_b, ...]))]
https://bazel.build/rules/config#accessing-attributes-with-transitions

?:0: attempt to perform arithmetic on field 'fileSize' (a nil value)

How to resolved error or possible ways to resolved it?
Guys, i've developed plugin using Lua language which can be integrate or run from Adobe's LightRoom Classic. Currently i need to upload or send a file to server but i can not. Everytime i called the POST API which is multipart/form-data error popup "?:0: attempt to perform arithmetic on field 'fileSize' (a nil value)". Not even API is being called this error pops up before API call. after debug I can assure the possible issue is in creating mimeChunks with file type.
I have developed the code like below, can any one help me out with suggestions so that i can able to resolved issue?
local filePath = assert("C:\Users\Ankit\Desktop\Hangman.PNG")
local fileName = LrPathUtils.leafName(filePath)
local mimeChunks = {}
mimeChunks[#mimeChunks + 1] = {
name = 'api_sig',
value = "test value"
}
mimeChunks[#mimeChunks + 1] = {
name = "file",
filePath = filePath,
fileName = fileName,
contentType = "application/octet-stream"
}
local postUrl = "API endpoint"
local result, hdrs = LrHttp.postMultipart(postUrl, mimeChunks)
if result then
LrDialogs.message("Form Values", result)
else
LrDialogs.message("Form Values", "API issue")
end
Eventually image or file path itself cause the issue, there are no such indications or articles related to this functionality, but yes "add-on backslash" will work out for sure. Kindly review the below code for more detailed bifurcation which pass dynamic selected file or image path.
local function uploadFile(filePath)
local fileName = LrPathUtils.leafName( filePath )
local mimeChunks = {}
mimeChunks[ #mimeChunks + 1 ] = { name = 'api_sig', value = "test value"}
mimeChunks[#mimeChunks + 1] = {
name = "file",
filePath = filePath,
fileName = fileName,
contentType = "image/jpeg" --multipart/form-data --application/octet-stream
}
import "LrTasks".startAsyncTask(
function()
local postUrl = "http://cms.local.com/api/v1/upload"
local result, hdrs = LrHttp.postMultipart(postUrl, mimeChunks)
if result then
LrDialogs.message("Image uploaded.", result)
else
LrDialogs.message("Error", "API issue")
end
end
)
end
Above uploadFile method will automatically call the API and post form-data collection. Below code is for call uploadFile function which select all the images from catalog.
for p, photo in ipairs(LrApplication.activeCatalog()) do
uploadFile(assert(photo:getRawMetadata('path')));
end
Above code will help you out the selection of categlog with Adobe's LightRoom Plugin.

Executing a native_binary inside a bazel rule

#bazel_skylib//rules:native_binary.bzl defines the native_binary rule which can be used to wrap native executables inside a bazel target. I used it to wrap a packaging tool called packfolder.exe from the Sciter SDK.
I placed the binary into my source tree at third_party/sciter/packfolder.exe and wrote this BUILD file.
# third_party/sciter/BUILD
native_binary(name = "packfolder",
src = "packfolder.exe",
out = "packfolder.exe"
)
bazel run third_party/sciter:packfolder runs with no issues. Now I want to use this target inside my custom cc_sciter_resource rule.
# third_party/sciter/sciter_rules.bzl
def _impl(ctx):
in_files = ctx.files.srcs
output_file = ctx.actions.declare_file(ctx.label.name)
ctx.actions.run(
outputs = [output_file],
inputs = in_files,
arguments = [],
executable = ctx.executable.packfolder.path)
return DefaultInfo(files = depset([output_file]))
cc_sciter_resource = rule(
implementation = _impl,
attrs = {
"srcs": attr.label_list(),
"packfolder": attr.label(
default = Label("//third_party/sciter:packfolder"),
executable = True,
cfg = "exec"
),
}
)
The trouble is, when I try to build a target that uses this rule, say
cc_sciter_resource(
name = "hello_world_resource.cpp"
srcs = [...]
)
I get the following error.
ERROR: C:/users/marki/sciter-bazel/examples/BUILD:12:19: Action examples/hello_world_resource.cpp failed (Exit -1): packfolder.exe failed: error executing command
cd C:/users/marki/_bazel_marki/kiodv2fz/execroot/sciter_bazel
bazel-out/x64_windows-opt-exec-2B5CBBC6/bin/third_party/sciter/packfolder.exe
Execution platform: #local_config_platform//:host. Note: Remote connection/protocol failed with: execution failed
Action failed to execute: java.io.IOException: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("C:\users\marki\_bazel_marki\kiodv2fz\execroot\sciter_bazel\bazel-out\x64_windows-opt-exec-2B5CBBC6\bin\third_party\sciter\packfolder.exe"): The system cannot find the file specified.
(error: 2)
Target //examples:hello_world_resource.cpp failed to build
The directory C:\users\marki\_bazel_marki\kiodv2fz\execroot\sciter_bazel\bazel-out\x64_windows-opt-exec-2B5CBBC6 does not exist on my computer. So the error is accurate, but I don't know how to resolve the issue.
--- sciter_rules.bzl
+++ sciter_rules.bzl
## -6,7 +6,7 ##
outputs = [output_file],
inputs = in_files,
arguments = [],
- executable = ctx.executable.packfolder.path)
+ executable = ctx.executable.packfolder)
return DefaultInfo(files = depset([output_file]))
cc_sciter_resource = rule(
ctx.executable.packfolder.path is just a string, so Bazel doesn't know that the packfolder executable needs to be added as an input to the action.

Select All Choices in Jenkins Groovy

I want to select all the choices in my Groovy script so it defaults to all. I am using the Active Choices Reactive Parameter because I am reading in the previous option. How do I make my "output" variable so it is all selected without having the user select them all?
def output = []
def line
def release = RELEASE_NUMBER
releaseNumber = release.replaceAll("\\n", "");
String[] number = releaseNumber.split("\\.");
def list = "cmd /c e:\\tools\\wget --no-check-certificate --http-user=username--http-password=password-qO- \"https://1.1.1.1:443/svn/Instructions/trunk/${number[0]}.${number[1]}.${number[2]}/ICAN/EI_${releaseNumber}.txt\"".execute().text
list.eachLine {
if (it.contains("- LH")) {
String newName = it.replaceAll("\\s", "");
String newName2 = newName.replaceAll("-", "");
output.add(newName2)
}
}
return output
I don't know anything about Jenkins, but reading the documentation for the plugin you mention you should be able to simply use output.add("${newName2}:selected").

Invalid argument supplied for foreach()

The code down below delete files inside the folder " Images " every 60 seconds, it works, but when the folder is empty it says: Warning: Invalid argument supplied for foreach()
How can that be fixed like if there is no files, say " folder empty instead of that warning..
<?php
$expiretime=1;
$tmpFolder="Images/";
$fileTypes="*.*";
foreach (glob($tmpFolder . $fileTypes) as $Filename) {
// Read file creation time
$FileCreationTime = filectime($Filename);
// Calculate file age in seconds
$FileAge = time() - $FileCreationTime;
// Is the file older than the given time span?
if ($FileAge > ($expiretime * 60)){
// Now do something with the olders files...
echo "The file $Filename is older than $expiretime minutes\r\n";
//delete files:
unlink($Filename);
}
}
?>
Since glob() may not reliably return an empty array for an empty match (See "note" in Return section of the docs), you just need an if statement protecting your loop, like so:
$files = glob($tmpFolder . $fileTypes);
if (is_array($files) && count($files) > 0) {
foreach($files as $Filename) {
// Read file creation time
$FileCreationTime = filectime($Filename);
// Calculate file age in seconds
$FileAge = time() - $FileCreationTime;
// Is the file older than the given time span?
if ($FileAge > ($expiretime * 60)){
// Now do something with the olders files...
echo "The file $Filename is older than $expiretime minutes\r\n";
//delete files:
unlink($Filename);
}
} else {
echo 'Your error here...';
}

Resources