2

I need to get DateTime during the deployment in a YAML file. The DateTime should be shown as

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

I found this help. but I need to follow the exact Datetime format. I wonder if anyone can help in this case?

-- Added --

I work on deploying Data Factory by YAML file. This StartTime will be DateTime for the trigger part of Data Factory pipeline

I have update my build pipeline with a variable, build.yml

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

and inside my deploy.yml file

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

and in adf.content.json, I added

"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/...')]"
    ]
ShrnPrmshr
  • 353
  • 2
  • 5
  • 17

2 Answers2

1

There is an environment variable in the release stage named RELEASE_DEPLOYMENT_STARTTIME and we can use it in powershell via $(Release.Deployment.StartTime)

enter image description here

In addition, we can custom the variable.

Note: I use the date format as yyyy-MM-dd HH:mm:ss here, You can use other date formats

Define variables

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

Output the variable

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

Result:

enter image description here

Update1

Please also check this ticket

Vito Liu
  • 7,525
  • 1
  • 8
  • 17
  • thanks for your answer! Actually I need this time inside variable to be able to assign it in a JSON file when I need it. I have tried this one: deployDate: $(Get-Date -Format "YYYYMMDDThhmmss") but it does not work – ShrnPrmshr Aug 26 '20 at 10:06
  • I follow this post: https://developercommunity.visualstudio.com/content/problem/824760/how-to-get-formatted-date-into-variable-in-a-azure.html – ShrnPrmshr Aug 26 '20 at 10:09
0

I managed to solve my problem. First of all, I removed all the changes I did in YAML files. and then I updated the only adf.content.json

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

and update the variable, I want to run 15min after the deploy

  "variables": {
    "startTime": "[dateTimeAdd(parameters('baseTime'), 'PT15M')]"
  }
ShrnPrmshr
  • 353
  • 2
  • 5
  • 17
  • Thanks for your sharing. You could accept your answer. In this case, others could directly find the useful solution. – Vito Liu Aug 27 '20 at 02:56
  • the only problem with this is that Data Factory does not allow you to change the time during each deploy. and this means each time I should delete the trigger before any deploy. @VitoLiu-MSFT do you have experience with this? – ShrnPrmshr Sep 21 '20 at 09:26