在Azure Pipelines中,如何在其他任务运行时执行后台任务? [英] In Azure Pipelines, how can I execute a background task while other tasks run?

查看:132
本文介绍了在Azure Pipelines中,如何在其他任务运行时执行后台任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在摆弄管道,以尝试减少总体运行时间.我想做的一件事是在开始时执行docker pull ...,以便稍后在我真正需要它时为我准备好了.我想将其作为后台工作开除,并使其在任务结束后仍然存在.

I'm fiddling with pipelines to try and reduce the overall runtime. One of the things I'd like to do is to execute docker pull ... at the start, so that later on, when I actually need it, it's ready for me. I'd like to fire it off as a background job, and have it survive past the end of that task.

我已经尝试过:docker pull imgname &

它确实起作用,但是管道抱怨此消息:

It does work, but the pipeline complains with this message:

STDIO流在退出事件后的10秒内未关闭 来自进程"/bin/bash".这可能表明子进程已继承 STDIO流并且尚未退出.

The STDIO streams did not close within 10 seconds of the exit event from process '/bin/bash'. This may indicate a child process inherited the STDIO streams and has not yet exited.

我也尝试过类似的事情:

I've also tried stuff like:

  • docker pull imgname </dev/null &>/dev/null & disown
  • docker pull imgname 0>&- 1>&- 2>&- 3>&- 4>&- 5>&- 6>&- 7>&- 8>&- 9>&- &
  • docker pull imgname </dev/null &>/dev/null & disown
  • docker pull imgname 0>&- 1>&- 2>&- 3>&- 4>&- 5>&- 6>&- 7>&- 8>&- 9>&- &

还有一些类似的技巧.没有任何帮助.

And a few similar tricks. Nothing helps.

这没什么大不了的,但是知道如何使之成为可能会很方便!

This isn't a big deal, but it would be convenient to know how to make this possible!

推荐答案

更新

STDIO流在退出事件后的10秒内未关闭 来自进程"/bin/bash".这可能表明子进程已继承 STDIO流并且尚未退出

The STDIO streams did not close within 10 seconds of the exit event from process '/bin/bash'. This may indicate a child process inherited the STDIO streams and has not yet exited

这不是一条没有写入标准错误流并且使任务失败的错误消息.

This is not an error message which didn't write into the standard error steam and fail the task.

它应该更像是一条提示消息,指示某些进程仍在运行并且尚未清理(预期行为).

It should be more like an prompting message which indicate some process still run and not be clean up (expected behavior).

在构建管道中启用调试模式后,我们可以看到

After enable the debug mode in the build pipeline, we could see

## [debug]该任务被标记为完成",但是该过程在5秒钟后仍未关闭.将任务视为已完成.

即使任务已标记为完成,该进程仍应作为后台运行.

The process should still be running as the background even though the task already marked completed.

根据您的描述,这似乎与docker命令或azure devops无关.

According to your description, this seems not related to docker command or azure devops side.

您只需要在后台运行Powershell脚本(涉及docker命令)即可.

You just need to run a powershell script (involve docker command) in background.

例如:在PowerShell任务中运行Start-Job,该脚本开始使用Receive-Job运行.当任务退出时,脚本停止.

For example: Run Start-Job inside a PowerShell Task, that script starts to run using the Receive-Job. When the task exits the script stops.

在PowerShell任务中,我运行以下命令:

In the PowerShell task I run the following:

Start-Job -FilePath "C:\build\BGGetFromNuGet.ps1" -ArgumentList "C:\build"

更多详细信息,请查看此链接-

More details please take a look at this link-- Start Job

如果您希望该脚本在任务完成后继续在后台运行.您可以尝试使用start-process命令启动脚本.这将确保任务完成后启动的作业继续运行.但是,构建完成后,该工作将被关闭.

If you want that script will continue to to run in the background while the task has finished. You could try to use start-process command to launch the script. This will make sure that the launched job keeps running when the task is finished. But the job will be closed when the build is finished.

Start-Process powershell.exe -ArgumentList '-file C:\build\BGGetFromNuGet.ps1'

这篇关于在Azure Pipelines中,如何在其他任务运行时执行后台任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆