2

I am aware of using following command to download files from Jenkins server if the workspace is anonymous access:

bitsadmin.exe /transfer replica /priority FOREGROUND http://1.1.1.1:8080/job/dump_data/ws/dump_data.zip %WORKSPACE%\dump_data.zip

But what if the Jenkins server is authenticated by username/password ?

EDIT: /setcredentials works, but one problem is that I can only use /create, /addfile, /resume, then /complete. How can I wait till transfer finish then continue the batch script?

EDIT: Further test shows /setcredential didn't work. The previous test shows it works because my Jenkins allow anonymous access at that time. I captured the packet when using the bitadmin. It shows http request is HEAD without any credential information. If I use curl-win to download, the http request is GET with basic authentication username and password.

3

If you need to set credentials on a BITS job, you'd use the /setcredentials switch.

 /SETCREDENTIALS job target scheme username password
     Adds credentials to a job.
     target may be either SERVER or PROXY
     scheme may be BASIC, DIGEST, NTLM, NEGOTIATE, or PASSPORT.

The excellent ss64 command reference for BITSadmin can be found here.

1
  • This works, but one problem is that I can only use /create, /addfile, /resume, then /complete. How can I wait till transfer finish then continue the batch script? – valpa Nov 27 '14 at 1:17
2

Here is a .bat script corresponding to the question:

bitsadmin /Create DownloadDumpData
bitsadmin /SetCredentials DownloadDumpData target scheme username password
bitsadmin /AddFile DownloadDumpData http://1.1.1.1:8080/job/dump_data/ws/dump_data.zip %WORKSPACE%\dump_data.zip
bitsadmin /SetPriority DownloadDumpData "FOREGROUND"
bitsadmin /Resume DownloadDumpData
:WAIT_DUMP_DATA_DOWNLOAD_LOOP_START
    @rem state thanks to http://ss64.com/nt/bitsadmin.html & http://serverfault.com/a/646948/93281
    call bitsadmin /info DownloadDumpData /verbose | find "STATE: TRANSFERRED"
    if %ERRORLEVEL% equ 0 goto WAIT_DUMP_DATA_DOWNLOAD_LOOP_END
    call bitsadmin /RawReturn /GetBytesTransferred DownloadDumpData
    @rem sleep thanks to http://stackoverflow.com/a/1672375/535203
    timeout 2
    goto WAIT_DUMP_DATA_DOWNLOAD_LOOP_START
:WAIT_DUMP_DATA_DOWNLOAD_LOOP_END
call bitsadmin /Complete DownloadDumpData
1
  • At least in Windows 10, /transfer (with optional /rawreturn) downloads synchronously. – George Sovetov Sep 3 '20 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.