gitlab-runner 已经以 --user gitlab-runner as service 方式启动,但是 pipeline 里执行 whoami 为什么还是 root?
stages:
- sonarqube-check
variables:
SONAR_HOST_URL: http://192.168.10.42:9000
SONAR_TOKEN: XXXX
sonarqube-check:
tags:
- ceshi
stage: sonarqube-check
image: mcr.microsoft.com/dotnet/core/sdk:latest
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: "0"
PROJECT_NAME: "XXXXX"
CI_DEBUG_TRACE: "true"
script:
#- "sudo apt-get update"
#- "sudo apt-get install --yes openjdk-11-jre"
- "export PATH=\"$PATH:$HOME/.dotnet/tools\""
- "export PATH=\"$PATH:/home/gitlab-runner/.dotnet/tools\""
#- "dotnet tool install --global dotnet-sonarscanner"
- "whoami"
- "cd ./src"
- "ls -lh"
#- "ls -lh /home/gitlab-runner/.dotnet/tools"
- "dotnet sonarscanner begin /k:$PROJECT_NAME /d:sonar.qualitygate.wait=true /d:sonar.qualitygate.timeout=300 /d:sonar.login=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" /d:\"sonar.verbose=true\" "
- "dotnet build"
- "dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""
allow_failure: false
only:
- main
++ export SONAR_HOST_URL=http://192.168.10.42:9000
++ SONAR_HOST_URL=http://192.168.10.42:9000
++ export SONAR_TOKEN=[MASKED]
++ SONAR_TOKEN=[MASKED]
++ export CI_DISPOSABLE_ENVIRONMENT=true
++ CI_DISPOSABLE_ENVIRONMENT=true
++ export CI_RUNNER_VERSION=14.9.1
++ CI_RUNNER_VERSION=14.9.1
++ export CI_RUNNER_REVISION=bd40e3da
++ CI_RUNNER_REVISION=bd40e3da
++ export CI_RUNNER_EXECUTABLE_ARCH=linux/amd64
++ CI_RUNNER_EXECUTABLE_ARCH=linux/amd64
++ cd /builds/devops1/sonarqube
++ echo '$ export PATH="$PATH:$HOME/.dotnet/tools"'
++ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools
++ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools
++ echo '$ export PATH="$PATH:/home/gitlab-runner/.dotnet/tools"'
++ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools:/home/gitlab-runner/.dotnet/tools
++ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools:/home/gitlab-runner/.dotnet/tools
++ echo '$ whoami'
++ whoami
$ export PATH="$PATH:$HOME/.dotnet/tools"
$ export PATH="$PATH:/home/gitlab-runner/.dotnet/tools"
$ whoami
root
$ cd ./src
$ ls -lh
++ echo '$ cd ./src'
++ cd ./src
++ echo '$ ls -lh'
++ ls -lh
total 200K
drwxrwxrwx 5 root root 4.0K Apr 14 09:01 Biz
drwxrwxrwx 4 root root 4.0K Apr 14 09:01 Data
drwxrwxrwx 5 root root 4.0K Apr 14 09:01 Infrastructure
-rw-rw-rw- 1 root root 12K Apr 14 09:01 MASA.DCC.sln
drwxrwxrwx 7 root root 4.0K Apr 14 09:01 Model
drwxrwxrwx 4 root root 4.0K Apr 14 09:01 Service
drwxrwxrwx 3 root root 4.0K Apr 14 09:01 UI
-rw-rw-rw- 1 root root 160K Apr 14 09:01 dccd.png
-rw-rw-rw- 1 root root 489 Apr 14 09:01 nuget.config
$ dotnet sonarscanner begin /k:$PROJECT_NAME /d:sonar.qualitygate.wait=true /d:sonar.qualitygate.timeout=300 /d:sonar.login="$SONAR_TOKEN" /d:"sonar.host.url=$SONAR_HOST_URL" /d:"sonar.verbose=true"
++ echo '$ dotnet sonarscanner begin /k:$PROJECT_NAME /d:sonar.qualitygate.wait=true /d:sonar.qualitygate.timeout=300 /d:sonar.login="$SONAR_TOKEN" /d:"sonar.host.url=$SONAR_HOST_URL" /d:"sonar.verbose=true"'
++ dotnet sonarscanner begin /k:MASA-Stack-MASA-DCC /d:sonar.qualitygate.wait=true /d:sonar.qualitygate.timeout=300 /d:sonar.login=[MASKED] /d:sonar.host.url=http://192.168.10.42:9000 /d:sonar.verbose=true
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-sonarscanner does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
ERROR: Job failed: exit code 1
导致运行时找不到工具,因为环境变量不存在,如果切换到gitlab-runner 用户 pipeline 是可以成功运行的。
顺带再问一个问题,使用 shell 的时候大部分都是 “ERROR: Job failed: exit code 1” 之类的报错,其实是在控制台上看是有错误详细信息的, pipeline 里是否有相关设置? 我只找到 CI_DEBUG_TRACE 但结果 不是我想象中的那样理想。