簡體   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