在YAML文件中进行部署期间获取日期时间

时间:2020-08-26 06:03:24

标签: deployment azure-devops yaml azure-data-factory

在部署过程中,我需要在YAML文件中获取DateTime。日期时间应显示为

"startTime": "2017-12-08T00:00:00"

我找到了this帮助。但我需要遵循确切的日期时间格式。我想知道在这种情况下是否有人可以提供帮助?

-添加-

我正在通过YAML文件部署Data Factory。此StartTime将是Data Factory管道的触发器部分的DateTime

我已使用变量build.yml更新了构建管道

variables:
  deployDate: $(Get-Date -Format "YYYYMMDDThhmmssZ")

并在我的deploy.yml文件中

 - task: AzureResourceGroupDeployment@2
      displayName: "Deploy Azure Data Factory Content"
          inputs:
            azureSubscription: ...
            action: ...
            resourceGroupName: ..
            location: ...
            templateLocation: ...
            csmFile: ...
            csmParametersFile: ...
            overrideParameters: >-
              - ...
              -triggerStartTime "$(deployDate)"
            deploymentMode: 'Incremental'

在adf.content.json中,我添加了

"parameters": {
    "triggerStartTime": {
    "type": "string"
  }
}



"name": "[concat(parameters('factoryName'), '/Trigger')]",
    "type": "Microsoft.DataFactory/factories/triggers",
    "apiVersion": "...",
    "properties": {
      "annotations": [],
      "runtimeState": "Started",
      "pipeline": {
        "pipelineReference": {
          "referenceName": "...",
          "type": "PipelineReference"
        },
        "parameters": {}
      },
      "type": "TumblingWindowTrigger",
      "typeProperties": {
        "frequency": "Hour",
        "interval": 1,
        "startTime": "[parameters('triggerStartTime')]",
        "delay": "00:00:00",
        "maxConcurrency": 50,
        "retryPolicy": {
          "intervalInSeconds": 30
        },
        "dependsOn": []
      }
    },
    "dependsOn": [
      "[concat(variables('factoryId'), '/pipelines/...')]"
    ]

2 个答案:

答案 0 :(得分:0)

在发布阶段有一个名为RELEASE_DEPLOYMENT_STARTTIME的环境变量,我们可以通过$(Release.Deployment.StartTime)在powershell中使用它

enter image description here

此外,我们可以自定义变量。

注意:我在这里使用日期格式为yyyy-MM-dd HH:mm:ss,可以使用其他date formats

定义变量

$date=$(Get-Date -Format "yyyy-MM-dd HH:mm:ss");
Write-Host ("##vso[task.setvariable variable=StartTime]$date")

输出变量

   Write-Host "The value of StartTime is : $($env:StartTime)"

结果:

enter image description here

更新1

也请检查此ticket

答案 1 :(得分:0)

我设法解决了我的问题。首先,我删除了在YAML文件中所做的所有更改。 然后我更新了唯一的adf.content.json

"parameters": {
   "baseTime": {
       "type": "string",
       "defaultValue": "[utcNow('u')]",
       "metadata": {
           "description": "Schedule will start one hour from this time."
     }
  }
}

并更新变量,我想在部署后运行15分钟

  "variables": {
    "startTime": "[dateTimeAdd(parameters('baseTime'), 'PT15M')]"
  }