如何使用Artifactory API从PowerShell创建存储库?

时间:2018-05-14 15:58:00

标签: powershell repository artifactory

我尝试使用Artifactory Rest API来创建存储库条目。

# Repository Create - This PowerShell script will create a repository

# Define the security protocol for https
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

# Credentials for create repo operation - change to your admin/password
# Note: this is an example - real code should use keyvault to retrieve credentials and use a service principle
$AF_USER = "admin"
$AF_PWD = ConvertTo-SecureString "password" -AsPlainText -Force  
$CREDS = New-Object System.Management.Automation.PSCredential ($AF_USER, $AF_PWD)  

# URL to test against
$Urlprefix = "https://yourartifactory.com/artifactory/api"
$repokey = "team-mvn-test-local"
$Json = @{key="team-mvn-test-local"; packageType="maven"; rclass="local";} | ConvertTo-Json

Invoke-RestMethod -Uri "$Urlprefix/repositories/$repokey" -body $Json -ContentType "application/json" -Method Put -Credential $CREDS -ErrorVariable RestError        

if ($RestError) {Write-Host "Failed to create $repokey"}  
Else            {write-host "$repokey Created"}

0 个答案:

没有答案