我正在尝试运行管道,但它失败并出现找不到我的文件的错误。
我的以下脚本运行完美,没有任何问题。它会搜索配置文件夹内的
delete.ini
文件。
name: Delete-Resources
trigger:
branches:
include:
- main
paths:
include:
- configuration/delete.ini
variables:
- template: common/Common-Variables.yml
pool:
vmImage: 'windows-latest'
steps:
- script: |
@echo off
setlocal
REM Read delete.ini file
set "INI_FILE=configuration\delete.ini"
echo INI_FILE=%INI_FILE%
type "%INI_FILE%"
REM Check delete flag using PowerShell
powershell -Command "$content = Get-Content -Path '%INI_FILE%'; if ($content -match 'delete\s*=\s*true') { echo 'Delete flag is set to true. Running Main_clean.ps1...'; exit 0 } else { echo 'Delete flag is not set to true. Skipping Main_clean.ps1 execution.'; exit 1 }"
REM Check the exit code of the PowerShell command
if %errorlevel% neq 0 (
echo Error: PowerShell command to check delete flag failed.
exit /b %errorlevel%
)
displayName: 'Check delete.ini for delete flag'
- task: AzurePowerShell@5
inputs:
azureSubscription: '$(serviceConnectionName)'
ScriptType: 'FilePath'
ScriptPath: 'infrastructure/Main_clean.ps1'
azurePowerShellVersion: 'LatestVersion'
condition: and(succeeded(), ne(variables['ShouldSkipMainClean'], 'true'))
但现在我尝试从部署作业中定位环境。所以我创建了名为
acsub
的环境并修改了我的 yaml 代码,如下所示。
name: Delete-Resources
trigger:
branches:
include:
- main
paths:
include:
- configuration/delete.ini
variables:
- template: common/Common-Variables.yml
pool:
vmImage: 'windows-latest'
jobs:
- deployment: DeleteResourcesDeployment
displayName: 'Delete Resources Deployment'
environment:
name: 'acsub'
pool:
vmImage: 'windows-latest'
strategy:
runOnce:
deploy:
steps:
- script: |
@echo off
setlocal
REM Set path to delete.ini file using agent build working directory
set "INI_FILE=$(Agent.BuildDirectory)\configuration\delete.ini"
echo INI_FILE=%INI_FILE%
type "%INI_FILE%"
REM Check delete flag using PowerShell
powershell -Command "$content = Get-Content -Path '%INI_FILE%'; if ($content -match 'delete\s*=\s*true') { echo 'Delete flag is set to true. Running Main_clean.ps1...'; exit 0 } else { echo 'Delete flag is not set to true. Skipping Main_clean.ps1 execution.'; exit 1 }"
REM Check the exit code of the PowerShell command
if %errorlevel% neq 0 (
echo Error: PowerShell command to check delete flag failed.
exit /b %errorlevel%
)
displayName: 'Check delete.ini for delete flag'
- task: AzurePowerShell@5
inputs:
azureSubscription: '$(serviceConnectionName)'
ScriptType: 'FilePath'
ScriptPath: 'infrastructure/Main_clean.ps1'
azurePowerShellVersion: 'LatestVersion'
condition: and(succeeded(), ne(variables['ShouldSkipMainClean'], 'true'))
但是找到存储库及其文件夹和文件时存在问题,
错误是这样的
INI_FILE=D: