0

我正在尝试在任务调度程序中运行 ps1 文件。该任务应该在每天晚上运行,历史表明它已经运行,

任务调度程序日志图像

但不是真的,因为我可以在 SonarQube 中看到它没有。

每个单独的步骤都按预期工作,如果我运行操作和命令一切都很好:

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\sonarqube\run_sonar_scan.ps1

而且我还尝试使用完整路径到 powershell

任务:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2020-07-27T13:10:30.3806911</Date>
    <Author>xxx\yyy</Author>
    <Description>Starts the SonarScanner bat files from run_sonar_scan.ps1</Description>
    <URI>\DdDRetail\SonarScanner</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2020-07-27T21:00:00</StartBoundary>
      <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-18</UserId>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>false</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
    <WakeToRun>true</WakeToRun>
    <ExecutionTimeLimit>PT8H</ExecutionTimeLimit>
    <Priority>7</Priority>
    <RestartOnFailure>
      <Interval>PT1M</Interval>
      <Count>3</Count>
    </RestartOnFailure>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>powershell.exe</Command>
      <Arguments>-NoProfile -ExecutionPolicy Bypass -File "C:\sonarqube\run_sonar_scan.ps1"</Arguments>
    </Exec>
  </Actions>
</Task>

ps1 文件:

$repo_file_path="C:\Users\xxx\source\repos"

Start-Process "cmd.exe"  "/c $repo_file_path\run_articleservice_scan.bat"

bat文件

  • 从 github 更新本地仓库
  • 更新 Nuget 包
  • 运行 SonarScanner
4

1 回答 1

1

无论用户是否登录,用户都需要是管理员或有权运行。用户已更改为管理员,一切正常,任务按预期执行。

于 2020-08-31T10:15:37.120 回答