2016-10-17 10 views
0

powershellを使用してアーティファクトをアップロードするにはどうすればよいですか?アーティファクトアップロードwithチェックサムwith powershell

バッシュ

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/ 

答えて

1

と次の作品使用Invoke-RestMethod

SHA1ハッシュを含める
$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 

ヘッダの一部として任意です。

ていることを確認してください:

  • 使用 '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