使用 powershell 进行带有校验和的人工上传

spu*_*der 2 artifactory

如何使用 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/
Run Code Online (Sandbox Code Playgroud)

spu*_*der 5

使用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
Run Code Online (Sandbox Code Playgroud)

包含 SHA1 哈希作为标头的一部分是可选的。

确保:

  • 使用“PUT”而不是“POST”
  • 文件名必须是 URI 的一部分

目前无法上传Sha256 校验和,而是需要通过 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
Run Code Online (Sandbox Code Playgroud)