小编rAJ*_*rAJ的帖子

引发了“Microsoft.Rest.Azure.CloudException”类型的异常

我正在尝试使用 VSTS 在 Web 应用程序上分配角色,但显示以下错误。

电源外壳 :

$webappname = "devt002"
$resourcegroup = "devt002RG"

#Get webapp object id
$webapp = Get-AzureRmWebApp -ResourceGroupName "$resourcegroup" -Name "$webappname"
$objectid = [System.Guid]::Parse($webapp.Identity.PrincipalId)
write-host "Object ID datatype :" $objectid.GetType().FullName
write-host "Object ID :" $objectid


#Get Assign role if already exist
$roles = Get-AzureRmRoleAssignment -ObjectId $objectid
write-host "Already Assigned Roles :" $roles.RoleDefinitionName
Run Code Online (Sandbox Code Playgroud)

错误 :

2019-04-05T11:20:23.7408185Z ##[debug]Caught exception from task script.
2019-04-05T11:20:23.7408790Z ##[debug]Error record:
2019-04-05T11:20:23.7408993Z ##[debug]Get-AzureRmRoleAssignment : Exception of type 'Microsoft.Rest.Azure.CloudException' was thrown.
Run Code Online (Sandbox Code Playgroud)

注意:它在本地 powershell 客户端中工作正常。仅 VSTS 存在问题。

powershell azure-devops

5
推荐指数
1
解决办法
3496
查看次数

使用 Powershell 从字符串中获取键值

我正在尝试在 powershell 中使用 Regex 获取键值。

$string = "key1:value1,key2:value2,key3:value3"
$name = [Regex]::Matches($string, ':([^/]+),') | Select -ExpandProperty Value
Write-Host "Name :" $name
Run Code Online (Sandbox Code Playgroud)

我想要这样的输出:

$key1 = "value1"
$key2 = "value2"
$key3 = "value3"
Run Code Online (Sandbox Code Playgroud)

我得到的输出:

Name : :value1,key2:value2,
Run Code Online (Sandbox Code Playgroud)

regex powershell

5
推荐指数
1
解决办法
2562
查看次数

使用 Groovy 脚本生成随机 16 位十六进制数

我正在尝试生成 16 位随机十六进制数。

import org.apache.commons.lang.RandomStringUtils;
def randomhex = RandomStringUtils.randomNumeric(16);
log.info randomhex
def result = Integer.toHexString(randomhex);
log.info result
Run Code Online (Sandbox Code Playgroud)

预期:结果应为随机 16 位十六进制数。例如:328A6D01F9FF12E0

实际:groovy.lang.MissingMethodException:没有方法签名:static java.lang.Integer.toHexString() 适用于参数类型:(java.lang.String) 值:[3912632387180714] 可能的解决方案:toHexString(int)、toString ()、toString()、toString()、toString(int)、toString(int, int) 错误位于第 9 行

groovy hex soapui

4
推荐指数
1
解决办法
5775
查看次数

Microsoft Graph API 创建事件始终使用 UTC 时区创建会议

我正在尝试使用 Graph API 创建会议创建一个事件,但它始终在 UTC 时区创建会议。

要求

POST https://graph.microsoft.com/v1.0/users/abc@xxx.onmicrosoft.com/calendar/events HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
Authorization: Bearer xxxxxx
Prefer: outlook.timezone="Asia/Kolkata"
Content-Length: 1016
Host: graph.microsoft.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

{
  "subject": "Meeting SoapUI 4",
  "body": {
    "contentType": "HTML",
    "content": "Please Ignore !!! This invitation coming from SoapUI automation utility."
  },
  "start": {
    "dateTime": "2020-06-05T19:30:00.000Z",
    "timeZone": "Asia/Kolkata"
  },
  "end": {
    "dateTime": "2020-06-05T20:00:00.000Z",
    "timeZone": "Asia/Kolkata"
  }
}
Run Code Online (Sandbox Code Playgroud)

回复

{
   "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('abc%40xxx.onmicrosoft.com')/calendar/events/$entity",
   "@odata.etag": "W/\"xxxx==\"",

   "originalStartTimeZone": "UTC",
   "originalEndTimeZone": "UTC",

   "subject": "MiniSync Meeting SoapUI 4", …
Run Code Online (Sandbox Code Playgroud)

api outlook timezone graph microsoft-graph-api

4
推荐指数
1
解决办法
5234
查看次数

在Groovy中将毫秒转换为yyyy-MM-dd日期时间格式

我想转换毫秒(例如:1503478800000),以YYYY-MM-DDTHH:MM:ss.SSS'Z"原(如:2017-08-23T09:00:000Z)日期 - 时间格式.存储在Soapui Global变量中的毫秒值.

def testCase = messageExchange.modelItem.testCase;
def NewDateTime = testCase.testSuite.project.getPropertyValue("StartDateTime").toInteger();
log.info NewDateTime.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Run Code Online (Sandbox Code Playgroud)

错误弹出显示: -

For input string: "1503478800000"
Run Code Online (Sandbox Code Playgroud)

groovy soapui

3
推荐指数
1
解决办法
3198
查看次数

实施重试逻辑后显示角色分配已存在错误

我正在尝试在设置系统分配的托管标识后将角色分配给网络应用程序。问题是,如果您在设置托管标识之后分配角色,则会抛出错误。

2019-04-04T07:57:12.9852397Z ##[error]Principal 438350e59xxxxxxxxxx935e5c135 does not exist in the directory ***.
Run Code Online (Sandbox Code Playgroud)

因此,我添加了重试代码来尝试分配角色,直到主体可用。

$webappname = "devt002"
$resourcegroup = "devt002RG"
$roleDefinitionName = "Storage Blob Data Contributor"

#Set the system assigned managed identity
Set-AzureRmWebApp -AssignIdentity $true -ResourceGroupName "$resourcegroup" -Name "$webappname"

#Get webapp object id
$webapp = Get-AzureRmWebApp -ResourceGroupName "$resourcegroup" -Name "$webappname"
$objectid = [System.Guid]::Parse($webapp.Identity.PrincipalId)
write-host "Object ID :" $objectid

#Get resource id (Scope) for storage account
$webapp2 = Get-AzureRmResource -ResourceGroupName "$resourcegroup" -Name "$webappname" -ResourceType "Microsoft.Storage/storageAccounts"
$resid = $webapp2.ResourceId.ToString()
write-host "Resource ID :" $resid …
Run Code Online (Sandbox Code Playgroud)

powershell azure azure-devops

3
推荐指数
1
解决办法
2万
查看次数

使用 Groovy 将日期解析为“yyyy-MM-dd'T'00:00:00”

我正在尝试将日期格式 '2017-12-18T20:41:06.136Z' 解析为“2017-12-18'T'00:00:00”

Date date = new Date();
def dateformat =  new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
dateformat.setTimeZone(TimeZone.getTimeZone(TimeZoneCode));
def currentDate = dateformat.format(date)
log.info "Current Date : " + currentDate
date1 =  new SimpleDateFormat("yyyy-MM-dd'T'00:00:00").parse(currentDate)
log.info "Current Date : " + date1
Run Code Online (Sandbox Code Playgroud)

显示错误:

java.text.ParseException:无法解析的日期:“2017-12-18T20:46:06:234Z”错误位于第:16行

这一行给出了错误:

date1 =  new SimpleDateFormat("yyyy-MM-dd'T'00:00:00").parse(currentDate)
Run Code Online (Sandbox Code Playgroud)

groovy datetime soapui datetime-format

2
推荐指数
1
解决办法
2万
查看次数

术语“System.DefaultWorkingDirectory”未被识别为 cmdlet 的名称

我正在尝试使用 VSTS 发布作业使用 powershell 生成 CSV 文件并将其存储到当前工作目录。奇怪的是,相同的代码以前运行良好。唯一的区别是以前我使用内联脚本,但现在我使用文件路径。

$results = @()

$data = 
@{                       
    uname = $uname             
    upass = "Apple@123"
    uid = $uid    
}

$results += New-Object PSObject -Property $data 

$results | export-csv -Path $(System.DefaultWorkingDirectory)\1UserTestDocument.csv -NoTypeInformation 

write-host "Print all files in the current directory :"
Get-Item *
Run Code Online (Sandbox Code Playgroud)

错误 :

2019-03-01T06:56:19.2333832Z VERBOSE: Importing function 'CmdletHasMember'.
2019-03-01T06:56:19.2515776Z VERBOSE: Importing function 'Disconnect-AzureAndClearContext'.
2019-03-01T06:56:19.2515900Z VERBOSE: Importing function 'Initialize-AzModule'.
2019-03-01T06:56:19.2515985Z VERBOSE: Importing function 'Initialize-Azure'.
2019-03-01T06:56:19.2516046Z VERBOSE: Importing function 'Initialize-AzureRMModule'.
2019-03-01T06:56:19.2516153Z VERBOSE: Importing function 'Remove-EndpointSecrets'.
2019-03-01T06:56:19.2516240Z VERBOSE: …
Run Code Online (Sandbox Code Playgroud)

powershell azure-devops

2
推荐指数
1
解决办法
2858
查看次数

Powershell中字符串内的Concat变量

我正在尝试在字符串中连接变量。

代码

$uniqueID = "123"
$Key = '<add key="uniqueID" value="$uniqueID" />'
write-host $Key
Run Code Online (Sandbox Code Playgroud)

结果我想要

<add key="uniqueID" value="123" />
Run Code Online (Sandbox Code Playgroud)

结果我得到

<add key="uniqueID" value="$uniqueID" />
Run Code Online (Sandbox Code Playgroud)

powershell

1
推荐指数
1
解决办法
8605
查看次数