【发布时间】:2020-05-25 07:30:43
【问题描述】:
我使用 Ubuntu 18.04 在 Azure 中创建了一个管道。我的要求是使用 bash 脚本运行 docker 映像,并创建了以下相同的脚本,但在执行时我收到错误“docker 命令不存在且 docker:无效的参考格式。
test.sh
#!/bin/bash
#
echo "=== docker Images==="
docker images
echo "==== Starut running a jmeter/image ===="
docker run "justb4/jmeter:latest"
echo "==== Finish ===="
错误
Starting: Bash Script scripts/test.sh
==============================================================================
Task : Bash
Description : Run a Bash script on macOS, Linux, or Windows
Version : 3.163.2
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================
Generating script.
Formatted command: bash '/home/vsts/work/1/s/scripts/test.sh' 'justb4/jmeter:latest' mainTest.jmx qa-url 30 1 60 15 2 60 1000
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /home/vsts/work/_temp/5c641c31-4e55-4ab8-be9e-4cf850432bab.sh
=== docker Images===
docker: 'images
' is not a docker command.
See 'docker --help'
==== Starut running a jmeter/image ====
docker: invalid reference format.
See 'docker run --help'.
==== Finish ====
Finishing: Bash Script scripts/test.sh
为了详细描述,这里是在 az pipeline 上创建的任务:-
1. Install a docker
Output of Task1
2. Just for debugging purpose, I added below bash task **with inline commands** to see if docker
命令工作,它工作得非常好,没有任何问题。但是在task3中,当我尝试执行 使用相同命令的脚本失败了。
Task2 的输出
3. Task 3 to execute test.sh script having docker commands
【问题讨论】:
-
我复制粘贴,一切都很好。您确定您的 test.sh 文件中的
docker和images之间没有任何多余的字符吗? -
感谢您对此进行调查并尝试一下。没有空格和其他字符。请您确认一下您是如何执行此脚本的。是在 Ubuntu 映像上还是通过 Azure 管道,与我在步骤中提到的方式相同。
-
我从 Azure Pipelines 运行脚本,并将
agent Specification设置为ubuntu-18.04` 步骤:-任务:Bash@3 displayName: 'Bash Script test.sh' 输入:targetType: filePath filePath: 。 /stackoverflow/36/test.sh ` -
你没有安装docker,不是必须的吗?我的任务与您上面提到的完全相同。仍然完整的 YAML 文件在这里:- 你能找出任何错误吗?池:名称:Azure Pipelines 步骤:-任务:DockerInstaller@0 displayName:'Install Docker 17.09.0-ce' -任务:Bash@3 displayName:'Bash Script scripts/test.sh' 输入:targetType:filePath filePath:。 /scripts/test.sh
-
此池中的图像预装了一些软件。例如,如果您不安装 docker a,您将使用已安装的版本,这在他的情况下是
Docker version 3.0.11+azure, build eb310fca49568dccd87c6136f774ef6fff2a1b51。但我做得更多。我在安装Docker version 17.09.0-ce, build afdb6d4之前和之后运行了 test.sh。在这两种情况下,它都对我有用。
标签: linux azure ubuntu azure-devops ubuntu-18.04