简体   繁体   中英

gitlab ci/cd ERROR: Job failed: exit code 1 on chmod og= $STAGE_ID_RSA

This is my ci.yml

deploy-stage:
  stage: deploy
  image: alpine:latest
  script:
    - chmod og= $STAGE_ID_RSA
    - apk update && apk add openssh-client
    - ssh -i $STAGE_ID_RSA -o StrictHostKeyChecking=no $STAGE_SERVER_USER@$STAGE_SERVER_IP "docker stop $CI_PROJECT_NAME || true"
    - ssh -i $STAGE_ID_RSA -o StrictHostKeyChecking=no $STAGE_SERVER_USER@$STAGE_SERVER_IP "docker rm $CI_PROJECT_NAME || true"
    - ssh -i $STAGE_ID_RSA -o StrictHostKeyChecking=no $STAGE_SERVER_USER@$STAGE_SERVER_IP "docker image rm $CI_REGISTRY_IMAGE:latest || true"
    - ssh -i $STAGE_ID_RSA -o StrictHostKeyChecking=no $STAGE_SERVER_USER@$STAGE_SERVER_IP "docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY"
    - ssh -i $STAGE_ID_RSA -o StrictHostKeyChecking=no $STAGE_SERVER_USER@$STAGE_SERVER_IP "docker pull $CI_REGISTRY_IMAGE:latest"
    - ssh -i $STAGE_ID_RSA -o StrictHostKeyChecking=no $STAGE_SERVER_USER@$STAGE_SERVER_IP "docker run -d --restart unless-stopped --name $CI_PROJECT_NAME -p 8882:4000 -e "variableData=Docker-Run-Command" $CI_REGISTRY_IMAGE:latest"

I get this error:

BusyBox v1.35.0 (2022-05-09 17:27:12 UTC) multi-call binary.
Usage: chmod [-Rcvf] MODE[,MODE]... FILE...
MODE is octal number (bit pattern sstrwxrwxrwx) or [ugoa]{+|-|=}[rwxXst]
    -R  Recurse
    -c  List changed files
    -v  Verbose
    -f  Hide errors
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

And this my variable:

https://i.stack.imgur.com/zegmz.png

And I enter breakline end of STAGE_ID_RSA value

First, you can use chmod og= -- $STAGE_ID_RSA to make sure chmod will not consider $STAGE_ID_RSA as an option, but a parameter .

Second, chmod [OPTIONS] [ugoa…][-+=]perms…[,…] FILE... means the chmod applies to a file .

If $STAGE_ID_RSA represents a value , that would not work.
You would need to redirect its content to a file.

Yet, I do see STAGE_ID_RSA here, used as you do in .gitlab-ci.yml , but using the kroniak/ssh-client rather than alpine:latest .

The chmod in alpine:latest might not behave like a chmod in a more traditional image.
See " Linux commands in Alpine docker image +755 invalid mode ".
That is most likely your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM