繁体   English   中英

用于为Azure数据工厂构建CI / CD的Powershell脚本

[英]Powershell script for building CI/CD for Azure Data factory

我计划使用PowerShell为Azure数据工厂构建持续集成和部署。 因此,所有可以使用VSTS完成的构建和发布过程都必须使用Powershell完成。 如果任何人都可以共享任何链接或Powershell脚本,那将很有帮助。 谢谢

如果要通过PowerShell创建构建/发布定义,则可以通过带有PowerShell的VSTS REST通过简单的代码来实现:

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "","{personal access token}")))
$body='{
    "variables": {
        "system.debug": {
            "value": "false",
            "allowOverride": true
        }
    },
    "retentionRules": [
        {
            "branches": [
                "+refs/heads/*"
            ],
            "artifacts": [],
            "artifactTypesToDelete": [
                "FilePath",
                "SymbolStore"
            ],
            "daysToKeep": 10,
            "minimumToKeep": 1,
            "deleteBuildRecord": true,
            "deleteTestResults": true
        }
    ],
    "properties": {},
    "tags": [],
    "jobAuthorizationScope": "projectCollection",
    "jobTimeoutInMinutes": 60,
    "jobCancelTimeoutInMinutes": 5,
    "process": {
        "phases": [
            {
                "steps": [
                    {
                        "environment": {},
                        "enabled": true,
                        "continueOnError": false,
                        "alwaysRun": false,
                        "displayName": "Azure PowerShell script: FilePath",
                        "timeoutInMinutes": 0,
                        "condition": "succeeded()",
                        "task": {
                            "id": "72a1931b-effb-4d2e-8fd8-f8472a07cb62",
                            "versionSpec": "2.*",
                            "definitionType": "task"
                        },
                        "inputs": {
                            "ConnectedServiceNameSelector": "ConnectedServiceNameARM",
                            "ConnectedServiceName": "",
                            "ConnectedServiceNameARM": "aad18bbf-0333-41bf-99ea-674181d17ada",
                            "ScriptType": "FilePath",
                            "ScriptPath": "$/Scrum2015/ClassLibraryA/dbtest.ps1",
                            "Inline": "# You can write your azure powershell scripts inline here. \n# You can also pass predefined and custom variables to this script using arguments",
                            "ScriptArguments": "",
                            "TargetAzurePs": "LatestVersion",
                            "CustomTargetAzurePs": ""
                        }
                    }
                ],
                "name": "Phase 1",
                "refName": "Phase_1",
                "condition": "succeeded()",
                "target": {
                    "executionOptions": {
                        "type": 0
                    },
                    "allowScriptsAuthAccessOption": false,
                    "type": 1
                },
                "jobAuthorizationScope": "projectCollection",
                "jobCancelTimeoutInMinutes": 1
            }
        ],
        "type": 1
    },
    "repository": {
        "properties": {
            "cleanOptions": "0",
            "tfvcMapping": "{\"mappings\":[{\"serverPath\":\"$/Scrum2015/ClassLibraryA\",\"mappingType\":\"map\",\"localPath\":\"\\\\\"},{\"serverPath\":\"$/Scrum2015/ClassLibraryA/VS2010UltimTrial.iso\",\"mappingType\":\"cloak\",\"localPath\":\"\"},{\"serverPath\":\"$/Scrum2015/ClassLibraryA/tools\",\"mappingType\":\"cloak\",\"localPath\":\"\"}]}",
            "labelSources": "0",
            "labelSourcesFormat": "$(build.buildNumber)"
        },
        "id": "$/",
        "type": "TfsVersionControl",
        "name": "Scrum2015",
        "defaultBranch": "$/Scrum2015/ClassLibraryA",
        "rootFolder": "$/Scrum2015",
        "clean": "false",
        "checkoutSubmodules": false
    },
    "processParameters": {},
    "quality": "definition",
    "drafts": [],
    "queue": { 
        "id": 179
    },

    "name": "PowerShellRest2VNext",
    "path": "\\",
    "type": "build",
    "queueStatus": "enabled"
}'
$result = Invoke-RestMethod -Uri $uri -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $body

请注意,您可以创建一个示例构建/发布定义,然后通过VSTS REST API获取它以获取JSON内容。

可以帮助您的博客: VSTS / TFS REST API:基础知识以及构建和发行版

如果您指的是自定义构建/发布任务,则可以参考“ 添加构建或发布任务” ,对于powershell,按如下所示更改执行:

"execution": {
    "PowerShell3": {
      "target": "Hello.ps1",
      "argumentFormat": ""
    }
}

关于部署azure数据工厂,您可以参考: 如何使用PowerShell编程方式部署Azure数据工厂管道及其依赖项 (不需要调用Login-AzureRMAccountSelect-AzureRMSubscrition ,只需将Azure PowerShell任务添加到构建/发布定义中即可)。

第三扩展: Azure数据工厂

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM