从詹金斯下载zip

时间:2018-08-02 14:29:21

标签: javascript typescript jenkins azure-pipelines-build-task

我正在构建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();
}

1 个答案:

答案 0 :(得分:1)

您的任务是否打算用作构建或发布任务?如果是发布任务,为什么不直接使用Jenkins的Artifacts? enter image description here

相关问题