【发布时间】:2022-08-14 22:06:15
【问题描述】:
我有这个 .gitlab-ci.yml 文件内容,例如:
.install-pre-reqs: &install-pre-reqs
image: ubuntu:20.04
before_script:
- apt-get update -y
- apt-get upgrade -y
- apt-get install -y zip unzip curl fastjar
- chmod +x deploy.sh
test:
<<: *install-pre-reqs
stage: test
script:
- echo \'test\'
- ./deploy.sh
- echo \"content\"
- exit 0
以及包含 curl 命令的 deploy.sh 脚本:
#!/bin/sh
curl -u \"admin:admin\" -X POST \"http://localhost:9998/rest/admin/system/restart\"
我希望能够通过 CI/CD 运行 curl 命令。当我在本地直接使用 curl 运行命令时,它可以正常工作。但是,配置的 CI/CD 管道会触发以下错误消息:
Executing \"step_script\" stage of the job script
00:32
Using docker image sha256:3bc6e9f30f51d2bbf9307fc9d0bdfc30caa38cf4e3b05a714230f9a9b3381d84 for ubuntu:20.04 with digest ubuntu@sha256:af5efa9c28de78b754777af9b4d850112cad01899a5d37d2617bb94dc63a49aa ...
$ apt-get update -y
Err:1 http://security.ubuntu.com/ubuntu focal-security InRelease
Could not connect to security.ubuntu.com:80 (185.125.190.39), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.38), connection timed out Could not connect to security.ubuntu.com:80 (185.125.190.36), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.39), connection timed out
Err:2 http://archive.ubuntu.com/ubuntu focal InRelease
Could not connect to archive.ubuntu.com:80 (91.189.91.39), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.36), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.38), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.39), connection timed out
Err:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Unable to connect to archive.ubuntu.com:http:
Err:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Unable to connect to archive.ubuntu.com:http:
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease Could not connect to archive.ubuntu.com:80 (91.189.91.39), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.36), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.38), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.39), connection timed out
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease Unable to connect to archive.ubuntu.com:http:
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease Unable to connect to archive.ubuntu.com:http:
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease Could not connect to security.ubuntu.com:80 (185.125.190.39), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.38), connection timed out Could not connect to security.ubuntu.com:80 (185.125.190.36), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.39), connection timed out
W: Some index files failed to download. They have been ignored, or old ones used instead.
$ apt-get upgrade -y
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
$ apt-get install -y zip unzip curl fastjar
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package zip
E: Unable to locate package unzip
E: Unable to locate package curl
E: Unable to locate package fastjar
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
我怎样才能解决这些问题并使 curl 命令在 gitlab 环境中运行而不会出现问题?
标签: bash ubuntu curl gitlab cicd