如何使用 powershell 上传 Artifactory ?
以下内容适用于 bash
ARTIFACT_MD5_CHECKSUM=$(md5sum /tmp/bar.zip | awk '{print $1}')
ARTIFACT_SHA1_CHECKSUM=$(shasum -a 1 /tmp/bar.zip | awk '{ print $1 }')
curl --upload-file "/tmp/bar.zip" --header "X-Checksum-MD5:${ARTIFACT_MD5_CHECKSUM}" --header "X-Checksum-Sha1:${ARTIFACT_SHA1_CHECKSUM}" -u "admin:${ARTIFACTORY_API_KEY}" -v https://artifactory.example.com/artifactory/foo/
最佳答案
使用Invoke-RestMethod
$password = ConvertTo-SecureString -AsPlainText -Force -String '<api_key>'
$cred = New-Object Management.Automation.PSCredential ('admin', $password)
$ARTIFACT_SHA1_CHECKSUM=$(Get-FileHash -Algorithm SHA1 c:\bar.zip).Hash
$HEADERS = @{"X-Checksum-SHA1"=$ARTIFACT_SHA1_CHECKSUM;};
Invoke-RestMethod -Uri https://artifactory.example.com/artifactory/foo/bar.zip -Method PUT -InFile c:\bar.zip -cred $cred -Headers $HEADERS
将 SHA1 哈希值作为 header 的一部分是可选的。
确保:
- 使用“PUT”而不是“POST”
- 文件名必须是 URI 的一部分
Sha256 校验和 can't currently be uploaded ,相反,他们的计算需要是 requested through the api.
$CONTENT = @{"repoKey"="nd-web-zips";"path"=$localFile} | ConvertTo-Json
# For some reason, the api doesn't like $cred, pass the api key in directly to the headers
$HEADERS2 = @{"X-JFrog-Art-Api"=$APIKEY}
Invoke-RestMethod -Uri https://artifactory.example.com/artifactory/api/checksum/sha256 -Method POST -Body $CONTENT -ContentType "application/json" -Headers $HEADERS2
关于使用 powershell 进行带有校验和的人工上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40096770/