我正在构建VSTS任务,并且试图从jenkins服务器下载zip。我知道如果我单击日志输出中的链接(用于调试),则URL为b / c,它将下载。我知道我的凭证正确b / .c,我能够查询服务器,并遍历所有内部版本号。这是我到目前为止要做的。错误是当我打开拉链时,出现意外的文件结尾。如果我将var blob = xhr.responseText
更改为var blob = xhr.response
,则我的zip压缩文件仅为1 kb(预期14,583)。如果我将其保留为xhr.responseText
,则我的下载文件为27,393 KB。文档说应该是xhr.response
,所以我在做什么错了?
export async function DownloadArtifact(build, buildDefName: string, targetDir: string, auth: string){
let requestUrl = `${build.url}artifact/${buildDefName}/*zip*/${buildDefName}_${build.id}.zip`;
console.log(`Download request: ${requestUrl}`);
console.log(`target directory: ${targetDir}`);
let xhr = new XMLHttpRequest();
xhr.open("GET", requestUrl, false);
xhr.setRequestHeader("Content-type", "Application/zip");
xhr.setRequestHeader("Authorization", `Basic ${auth}`);
xhr.responseType = 'arraybuffer';
xhr.onload = async function(e){
let tmpName : string = tmp.tmpNameSync();
tmpName = tmpName + ".zip";
console.log(`File Name: ${tmpName}`);
var blob = xhr.responseText;
await fs.writeFile(tmpName, blob, function(err){
if(err)
{
console.log(err);
return;
}
console.log(`Writing file ${tmpName}`);
console.log(`##vso[task.setvariable variable=gameZipPath;isSecret=false;isOutput=true;]${tmpName}`);
});
}
xhr.send();
}