您如何使用PowerShell上传工件?
以下适用于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/
答案 0 :(得分:2)
使用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哈希作为标题的一部分包含在内是可选的。
确保:
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