You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VSTS发布定义的PowerShell任务中传入参数替代JSON配置项

How to Pass VSTS Release Parameters to PowerShell Script Instead of Reading from JSON

Got it, let's walk through this step by step to get your script pulling those four config values from VSTS release arguments instead of the JSON file:

Step 1: Revise the PowerShell Script (webjobs Stop.ps1)

Update the script to accept the four required parameters directly, and only keep the JSON read for the webJobs list. I've also fixed a few minor issues in the original script:

param(
    [string]$currentEnv,
    [string]$userName,
    [string]$password,
    [string]$webAppName,
    [string]$resourceGroup
)

# Only fetch the webJobs array from the JSON file now
[object]$paramObj = Get-Content "d:\a\r1\a\Jobs\WebJobs_scripts\WebJob_list.json" | ConvertFrom-Json
[object[]]$webJobs = $paramObj.$currentEnv.webJobs

# Optional: Add Azure authentication if your script doesn't handle it already
# $securePassword = ConvertTo-SecureString $password -AsPlainText -Force
# $credential = New-Object System.Management.Automation.PSCredential ($userName, $securePassword)
# Connect-AzAccount -Credential $credential -ServicePrincipal -TenantId "your-tenant-id"

foreach($wj in $webjobs)
{
    if($wj.typeName -eq "continuous")
    {
        Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroup -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName "$webAppName/$($wj.name)" -Action stop -ApiVersion 2015-08-01 -Force
        Write-Host "Successfully stopped continuous web job: $($wj.name)"
    }
}

Notes:

  • I updated the Write-Host output to be more descriptive for debugging
  • Added optional Azure authentication code (uncomment and adjust if your script wasn't handling login)
  • If you're using newer Azure modules, swap Invoke-AzureRmResourceAction with Invoke-AzResourceAction

Step 2: Clean Up the webjob_list.json File

Remove the four config fields we're now passing as parameters — only keep the webJobs array:

{
  "Dev": {
    "webJobs": [
      {
        "name": "webjobname",
        "typeName": "continuous"
      },
      {
        "name": "webjobname",
        "typeName": "continuous"
      },
      {
        "name": "webjobname",
        "typeName": "continuous"
      },
      {
        "name": "webjobname",
        "typeName": "continuous"
      }
    ]
  }
}

Step 3: Configure VSTS Release Definition

In your release definition's PowerShell task, navigate to the Arguments field and pass the parameters like this:

-currentEnv "Dev" -userName "abc-dev\$abcjobs-dev" -password "$(WebJobPassword)" -webAppName "abcjobs-dev" -resourceGroup "abc-Dev"

Critical Best Practice for Secrets

Never hardcode passwords in arguments! Instead:

  1. Go to your Azure DevOps project > Library > Variable Groups
  2. Create a secret variable (e.g., WebJobPassword) and paste your password
  3. Link the variable group to your release definition
  4. Use $(WebJobPassword) in the arguments — Azure DevOps will mask this value in logs automatically.

Step 4: Test the Release

Run your release to confirm the script receives all parameters correctly and stops the continuous web jobs as expected. You can add temporary Write-Host statements (avoid logging the password!) to debug parameter values if needed.


内容的提问来源于stack exchange,提问作者PDBR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 09:05:01