升级后Gitlab管道损坏

问题描述 投票:0回答:1

我最近将 gitlab 运行程序更新到 16.4.1,突然我的管道停止工作。我不知道是什么原因导致这种状态。在此升级之前,一切正常。

Pipeline 非常简单 - 它只是通过 SSH 连接到服务器并以特定用户身份运行脚本。我尝试以机器上的用户身份运行此脚本,并且运行良好。现在看来,Gitlab 完全忽略了管道的脚本部分。所有变量均已正确设置且可访问。

my-pipeline:
  stage: deploy
  rules:
    - if: '$PROJECT_IDENTIFIER != null && $CI_PIPELINE_SOURCE == "web"'
      when: always
    - when: never
  before_script:
    - apk add --update --no-cache openssh
    - install -m 600 -D /dev/null ~/.ssh/id_rsa
    - echo "$SSH_PRIVATE_KEY" | base64 -d > ~/.ssh/id_rsa
    - ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts
  script:
    - echo "start"
    - ssh $SSH_USER@$SSH_HOST "bash /scripts/myScript.sh $PROJECT_IDENTIFIER && exit"
    - echo "stop"
  after_script:
    - rm -rf ~/.ssh

输出就像

Running with gitlab-runner 16.4.1 (XXX) on docker-runner XXX, system ID: XXX
Preparing the "docker" executor
Using Docker executor with image alpine:latest ...
Pulling docker image alpine:latest ...
Using docker image XXX for alpine:latest with digest XXXX ...
Preparing environment
Running on runner XXX
Getting source from Git repository
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in XXX
Checking out 46e2c9a7 as detached HEAD (ref is main)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
Using docker image XXX for alpine:latest with digest alpine@sha256:XXX ...
$ apk add --update --no-cache openssh
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
(1/10) Installing openssh-keygen (9.3_p2-r0)
(2/10) Installing ncurses-terminfo-base (6.4_p20230506-r0)
(3/10) Installing libncursesw (6.4_p20230506-r0)
(4/10) Installing libedit (20221030.3.1-r1)
(5/10) Installing openssh-client-common (9.3_p2-r0)
(6/10) Installing openssh-client-default (9.3_p2-r0)
(7/10) Installing openssh-sftp-server (9.3_p2-r0)
(8/10) Installing openssh-server-common (9.3_p2-r0)
(9/10) Installing openssh-server (9.3_p2-r0)
(10/10) Installing openssh (9.3_p2-r0)
Executing busybox-1.36.1-r2.trigger
OK: 14 MiB in 25 packages
$ install -m 600 -D /dev/null ~/.ssh/id_rsa
$ echo "$SSH_PRIVATE_KEY" | base64 -d > ~/.ssh/id_rsa
$ ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts
Running after_script
Running after script...
$ rm -rf ~/.ssh
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1

有人知道为什么我的管道根本不处理脚本部分吗?

gitlab gitlab-ci pipeline gitlab-ci-runner
1个回答
0
投票

经过几个小时的挣扎,我放弃了并完全改变了管道。这是与上面版本相同的版本。我希望它可以帮助任何和我面临同样问题的人。

my-pipeline:
  stage: deploy
  rules:
    - if: '$PROJECT_IDENTIFIER != null && $CI_PIPELINE_SOURCE == "web"'
      when: always
    - when: never
  before_script:
    - apk add --no-cache openssh-client bash
    - mkdir -p ~/.ssh
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    - echo $SSH_PRIVATE_KEY | base64 -d > id_rsa
    - chmod 700 id_rsa
    - mv id_rsa ~/.ssh/id_rsa
  script:
    - ssh $SSH_USER@$SSH_HOST "bash /scripts/myScript.sh $PROJECT_IDENTIFIER"
  after_script:
    - rm -rf ~/.ssh
© www.soinside.com 2019 - 2024. All rights reserved.