2017-03-27 18 views
0

この質問は、Octopus Deployを使用してスケジュールされたタスクを実行するすべてのユーザー向けです。スケジュールされたタスクでのパラメータ:Octopus Windowsスケジュールされたタスクを展開する

https://library.octopusdeploy.com/step-template/actiontemplate-windows-scheduled-task-create

はあなたが指定する必要があります誰も遭遇した状況は、「(オプション)で起動し、」いますか?

これはOctopus Deployで可能かどうか、また回避策があるのでしょうか?

+0

「で起動します(オプション):」 – ProgSky

+0

タコの返信:私はこの質問があまりにもないよう求めていた私は、カスタム・ステップで行っていたところ

はまた、ここにある、それだけでPowerShellのです長い間、残念なことに、ステップテンプレートは主にコミュニティによって作成され、管理されています。あなたの最善の選択肢は、ステップテンプレートのコピーを作成し、あなた自身のセクションに/スクリプトを追加して "開始"フィールドを編集することです。 悲しいことに、実際にはここに他のオプションはありません。私たちは、ステップテンプレートを使用してコミュニティ貢献に多くを依存しています。あなたがこれを行うならば、私たちはあなたの修正でPRを見たいと思うでしょう。 以下のリンクは、図書館への投稿方法についての情報を提供しています。 https://github.com/OctopusDeploy/Library – ProgSky

答えて

1

Octopus deployコミュニティステップは、変数付きのPowershellスクリプトです。 Powershellを編集して、 "Start in"パスの誰かの変数を設定し、それをスケジュールされたタスクに渡すことができます。私はあなたに必要な例を与えることができます。

更新

タスクの上流階級のスクリプトを見て精度の後、私はより良いオプションは、タスクのパラメータを定義するXMLファイルのための単一のパラメータを追加することだと思うし、あなたのタコの展開内であることを設定しますステップ。これは、「開始」パラメータ以外の他のパラメータを指定する必要がある場合に備えて、最も固執性の高いものになります。

アップデート2

だから私は、愚かな私に、コミュニティフィードを見て、あなたが望んで行うには、カスタムステップを書きました。すでにXMLファイルからスケジュールされたタスクを作成するためのテンプレートがあります。 XMLによって作業ディレクトリを設定できます。ステップテンプレートは "XMLからスケジュールされたタスクを作成"と呼ばれ、http://library.octopusdeploy.com/step-templates/26c779af-4cce-447e-98bb-4741c25e0b3c/actiontemplate-create-scheduled-tasks-from-xmlにあります。

言うことを意図
$ErrorActionPreference = "Stop"; 
Set-StrictMode -Version "Latest"; 

function New-ScheduledTask { 
    param (
     [Parameter(Mandatory = $true)][hashtable] $octopusParameters 
    ) 

    $arguments = @{ 
     TaskName = $octopusParameters['TaskName'] 
     User = $octopusParameters['RunAsUser'] 
    } 

    if ($octopusParameters['RunAsPassword']) { 
     $arguments.Password = $runAsPassword 
    } 

    if ($octopusParameters.ContainsKey('RunWithElevatedPermissions')) { 
     if ([boolean]::Parse($octopusParameters['RunWithElevatedPermissions'])) { 
      $arguments.RunLevel = 'Highest' 
     } 
    } 

    switch ($octopusParameters['Schedule']) { 
     'Once' { 
      $triggerArguments.Once = $true 
      $triggerArguments.At = $runAt 
     } 
     'Daily' { 
      $triggerArguments.Daily = $true 
      $triggerArguments.At = $runAt 

      if ($interval) { 
       $triggerArguments.DaysInterval = $octopusParameters['Interval'] 
      } 
     } 
     'Weekly' { 
      $triggerArguments.Weekly = $true 
      $triggerArguments.At = $runAt 

      if ($interval) { 
       $triggerArguments.WeeksInterval = $octopusParameters['Interval'] 
      } 
     } 
     'Startup' { 
      $triggerArguments.AtStartup = $true 
     } 
     'Logon' { 
      $triggerArguments.AtLogOn = $true 
     } 
    } 

    $actionArguments = @{ 
     Execute = $octopusParameters['Executable'] 
     Argument = $octopusParameters['Arguments'] 
     WorkingDirectory = $octopusParameters['WorkingDirectory'] 
    } 
    $arguments.Action = New-ScheduledTaskAction @actionArguments 

    $triggerArguments = @{ 
     TaskName = $taskName 
     User = $runAsUser 
    } 
    $arguments.Trigger = New-ScheduledTaskTrigger @triggerArguments 

    Write-Output "Creating Scheduled Task - $taskName" 

    Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction:SilentlyContinue 
    Register-ScheduledTask @arguments | Out-Null 

    Write-Output "Successfully Created $taskName" 
} 

# only execute the step if it's called from octopus deploy, 
# and skip it if we're runnning inside a Pester test 
if (Test-Path -Path "Variable:octopusParameters") { 
    New-ScheduledTask $octopusParameters 
} 
+0

ありがとうございました。 – ProgSky

+0

Windows 2012または2016で動作していますか? Powershell 3には新しいAPIが用意されているため、タスクを簡単に作成できますが、v3はWindows 8,10、2012、および2016のデフォルトでのみ使用できます。 –

+0

私はWindows 2012で動作しています。 – ProgSky

関連する問題