我对 SpecFlow 有问题。我们正在使用 Azure Devops,当我在本地机器上构建解决方案时,它运行良好,但在 Azure Devops 构建期间,我收到以下错误:
[error]C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\specflow.tools.msbuild.generation\3.1.86\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): Error MSB4018: The "GenerateFeatureFileCodeBehindTask" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'. The system cannot find the file specified.
File name: 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at …Run Code Online (Sandbox Code Playgroud) 我真的是Azure平台的新手,也许这是一个愚蠢的问题,但我找不到有关这个主题的信息.我真的需要帮助.我正在为大学项目部署Web服务使用的数据库.在这个数据库中,我有一个存储过程,需要每天运行它.
发现使用Azure自动化,您可以编程或安排此类操作.我"安装"了该服务,我正在尝试创建"Runbook",但不知道如何在这里编写代码或代码,因为我从未使用过PowerShell.
任何帮助将不胜感激.提前致谢!
编辑1:
所以我正在尝试使用这段代码来制作魔法:
workflow WORKFLOW_NAME
{
param(
)
inlinescript {
# Define the connection to the SQL Database
$Conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=SERVER_NAME.database.windows.net;Initial Catalog=DATABASE_NAME;Integrated Security=False;User ID=USERNAME;Password=PASSWORD;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False")
# Open the SQL connection
$Conn.Open()
# Define the SQL command to run.
$Cmd=new-object system.Data.SqlClient.SqlCommand("exec PROCEDURE_NAME", $Conn)
$Cmd.CommandTimeout=120
# Execute the SQL command
$Da=New-Object system.Data.SqlClient.SqlDataAdapter($Cmd)
# Close the SQL connection
$Conn.Close()
}
}
Run Code Online (Sandbox Code Playgroud)
问题在于,当我保存RunBook并发布它时,它表示没有错误.当我运行RunBook时,它启动并完成发送没有错误或异常,所以你可以期望它能正常工作吗?但是在咨询数据库时,程序中没有修改过程.这可能是什么错误?我究竟做错了什么?
我从https://gallery.technet.microsoft.com/scriptcenter/How-to-use-a-SQL-Command-be77f9d2#content中获取了参考代码,对其进行了个性化并摆脱了"param",因为RunBook何时开始,从未要求任何输入参数,所以我决定使用完整的连接字符串.我使用与我的c#项目相同的连接字符串,它连接并完美地工作.
我正在使用"新"天蓝色界面,不知道这在这方面是否具有任何重要性.
再次感谢您提供的任何帮助.
powershell automation azure azure-automation azure-sql-database
更新:
好像其他人有同样的问题并报告了它.
从Azure自动化Runbook调用时,我遇到了一个简单的PowerShell脚本问题.在本地运行它时,同一段代码完美无瑕.
我已使用密码凭据在Azure Active Directory(托管在Azure德语云中)中添加了服务主体,并授予其参与者对订阅的访问权限(也在Azure德语云中托管).
Azure自动化服务托管在北欧,因为它目前在Azure德国云中不可用.
我尝试做的就是使用Add-AzureRmAccountcmdlet 使用上面提到的主体登录我的订阅.之后,我尝试使用Set-AzureRmContext并设置当前上下文并获取以下错误消息:
Set-AzureRmContext : Please provide a valid tenant or a valid subscription.
At line:26 char:1
+ Set-AzureRmContext -TenantId $TenantId -Su ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureRmContext], ArgumentException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand
Run Code Online (Sandbox Code Playgroud)
这是我尝试运行的脚本(将配置留空):
$TenantId = ""
$ApplicationId = ""
$ClientSecret = ""
$SubscriptionId = ""
$secpasswd = ConvertTo-SecureString $ClientSecret -AsPlainText -Force
$mycreds = New-Object …Run Code Online (Sandbox Code Playgroud)
我使用azure自动化,
并有这样的代码
workflow Report
{
param
(
[parameter(Mandatory=$True)]
[string] $Name,
[parameter(Mandatory=$true)]
[Int] $MyCount
)
inlinescript
{
Write-Verbose "Name $Name"
Write-Verbose "Count $MyCount"
}
}
Run Code Online (Sandbox Code Playgroud)
在测试窗格中(在https://portal.azure.com上)我为这些参数设置了下一个值:"Test"和2
在控制台中我看到下一个结果:
Name Test
Count
Run Code Online (Sandbox Code Playgroud)
$名称工作正常,
但$ MyCount没有显示
根据文档我正在做的一切正确
https://technet.microsoft.com/en-us/library/hh847743.aspx
我如何使用int输入参数?
我在为 Azure Web 应用程序设置 ARM 模板时遇到问题,因为我无法添加 ConnectionString 参数,如果设置了参数,它会在其中设置值,但如果未设置参数,则留空(默认)。
下面是它在 template.json 文件中的样子:
"connectionStrings": [
{
"name": "[parameters('connString').connName)]",
"connectionString": "[parameters('connString').string]",
"type": "[parameters('connString').connType]"
}
],
Run Code Online (Sandbox Code Playgroud)
在 parameters.json 文件中:
"connString": {
"value": {
"connName": "",
"string": "",
"connType": ""
}
},
Run Code Online (Sandbox Code Playgroud)
当使用上述方式运行部署时,它在“参数名称不能为空”时失败我尝试使用 equals 函数将值设置为空,如果参数为空,但如果参数已填写,则设置参数,但它没有不喜欢空值。
"name": "[if(equals(parameters('connString').connName,''),'',parameters('connString').connName)]"
Run Code Online (Sandbox Code Playgroud)
还尝试了一个空函数:
"name": "[not(empty(parameters('connString').connName))]"
Run Code Online (Sandbox Code Playgroud)
但是,如果为空,则返回“False”,如果设置了参数,则返回“True”(按设计)
如果我将虚拟值设置为参数,部署工作正常,是否可以设置一个函数或类似的东西,所以如果参数为空,它使用发送的任何值,就好像模板中不存在 connectionStrings 部分一样?这些参数是可选的,但看起来是因为它们在实际的 template.json 文件中,它需要一个值。
干杯
编辑 要发布我的最终模板的样子,以防其他人需要帮助。
模板文件
变量
"variables": {
"empty": []
},
Run Code Online (Sandbox Code Playgroud)
资源
"connectionStrings": "[if(empty(parameters('connString')), variables('empty'), array(parameters('connString')))]",
Run Code Online (Sandbox Code Playgroud)
参数文件
如果设置连接字符串
"connString": {
"value": [{
"name": "test",
"connectionString": "ufgndjkngsdgjkn",
"type": "Custom"
}]
}, …Run Code Online (Sandbox Code Playgroud) azure azure-automation azure-web-app-service azure-rm-template
我想将信息日志写入 Azure 自动化作业日志。我已经创建了简单的 PowerShell 运行手册
$InformationPreference = "Continue"
Write-Information "Hello info"
Write-Verbose "Hello Verbose"
Write-Warning "Hello warning"
Write-Error "Hello error"
Run Code Online (Sandbox Code Playgroud)
在 Runbook 执行中所有日志我只看到详细、警告和错误日志
如果要禁用 Runbook Verbose 日志,我只会看到警告和错误。它在本地工作正常,但在 Azure 中则不行。我也试过Write-Information "Hello info" -InformationAction Continue- 没有帮助。
Write-Information出现在 PowerShell 5.0 中。我已经通过使用检查了 Azure 自动化沙箱机器中的 PS 版本$PSVersionTable- 它超过 5。所以,应该可以工作。
你知道他们支持不支持吗?
我们在 Azure 虚拟机中运行节点应用程序,同时我们也想在某个时间借助 Azure 自动化(或通过管理门户)重新启动 VM。
但是VM重启后如何重启node应用呢?
我们尝试了很多方法来实现这一点,包括添加任务计划程序、将命令添加到注册表项 ( LocalMachine\..\Run)、使用 VM 的自定义脚本扩展......
以上都失败了。我们想要的是在虚拟机重启后,节点应用程序可以自动启动。如果我们然后使用预定义的帐户远程访问 VM,则上述一些方法可以工作。然而,这不是风景,我们只想在一开始就远程一次,而不是每次重启。
那么,实现此目的的正确方法是在VM自动重启后启动进程或执行命令而无需手动登录?
powershell startupscript azure azure-virtual-machine azure-automation
作为模板的一部分,我想要检索OMS/Operational Insights工作区的SharedKeys,而不是必须将其作为参数传递.
这可能吗?我在这里关注文档
Microsoft.OperationalInsights/workspaces/资源提供程序似乎没有任何list*提供程序操作,我找不到任何其他的引用:
Get-AzureRmProviderOperation -OperationSearchString * | where {$_.Operation -like "*operational*sharedkeys*"} | FT Operation
Microsoft.OperationalInsights/workspaces/sharedKeys/action
Run Code Online (Sandbox Code Playgroud)
我想要的用法:
"variables": { workspaceKey: "[listKeys(parameters('workspaceResourceId'), '2015-05-01-preview').primarySharedKey]" }
Run Code Online (Sandbox Code Playgroud)
在此期间,假设实际上不支持此功能,我在Log Analytics UserVoice站点上添加了对它的请求
json azure azure-resource-manager azure-automation azure-rm-template
当我尝试将变量部署到 Azure 自动化资产时,出现错误并且无法部署我的资源。
假设这个模板
{
"name": "myVariable",
"type": "Microsoft.Automation/automationAccounts/variables",
"apiVersion": "2015-10-31",
"dependsOn": [
"[resourceId('Microsoft.Automation/automationAccounts', variables('automationAccountName'))]"
],
"location": "[variables('automationLocation')]",
"properties": {
"isEncrypted": "false",
"value": "8f703df8-0448-4ee3-8629-fc3f01840683"
}
}
Run Code Online (Sandbox Code Playgroud)
部署向我抛出异常:
{\"Message\":\"The request is invalid.\",\"ModelState\":{\"variable.properties.value\":[\"Invalid JSON primitive: a7d14fb0-232e-4fa0-a748-c7c8fb2082e2.\"]}}
我也尝试过:
"value": "\"8f703df8-0448-4ee3-8629-fc3f01840683\""
Run Code Online (Sandbox Code Playgroud)
但是任何尝试都失败了!
任何人都知道如何使用 ARM 模板配置可变资产?
azure azure-resource-manager azure-automation azure-rm-template
我创建了一个示例 Azure 自动化 Powershell Runbook。我正在尝试执行 SQL 命令,然后将该命令中的消息打印到 Workbook 输出中。
我的代码取自使用 PowerShell 从 SQL Server 捕获 InfoMessage 输出,如果我在本地运行它,它就可以工作:
Write-Output "Starting"
$conn = New-Object System.Data.SqlClient.SqlConnection "Data Source=abc.database.windows.net,1433;Initial Catalog=def;Integrated Security=False;User ID=ghj;Password=qwe"
## Attach the InfoMessage Event Handler to the connection to write out the messages
$handler = [System.Data.SqlClient.SqlInfoMessageEventHandler] {param($sender, $event) Write-Output $event.Message };
$conn.add_InfoMessage($handler);
$conn.FireInfoMessageEventOnUserErrors = $true;
$conn.Open();
$cmd = $conn.CreateCommand();
$cmd.CommandText = "PRINT 'This is the message from the PRINT statement'";
$cmd.ExecuteNonQuery();
$cmd.CommandText = "RAISERROR('This is the message from the …Run Code Online (Sandbox Code Playgroud) azure-automation ×10
azure ×9
powershell ×5
automation ×1
azure-devops ×1
azure-mcd ×1
json ×1
logging ×1
nunit ×1
selenium ×1
specflow ×1
sql-server ×1