如何在Azure Runbook工作流中获取时间戳

时间:2019-01-17 00:24:41

标签: azure workflow azure-runbook

写输出行时,我试图获取一个时间戳。我尝试了几件事,最后以:

@object.__new__
class FileStructure(object): # Root directory
    root = "root"

    @object.__new__
    class details(object): # details directory
        root = "details"
        @property
        def file1(self):
            return os.path.join(str(self), 'file1')
        @property
        def file2(self):
            return os.path.join(str(self), 'file2')

        def __str__(self):
            return f"{os.path.join(FileStructure.root, self.root)}"

    def __str__(self):
        return f"{self.root}"

但这给了我错误:

filter timestamp {"$(Get-Date -Format G): $_"}
Write-Output "JOB START BEFORE INLINESCRIPT" | timestamp

执行此操作的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

您应该将代码放在InlineScript块中,如下所示:

workflow MyFirstRunbook-Workflow
{   
   INLINESCRIPT{
    write-output "hello world"
    filter timestamp {"$(Get-Date -Format G): $_"}
    write-output "JOB START BEFORE INLINESCRIPT" | timestamp
   }    
}

测试结果:

enter image description here