我正在使用谷歌云构建来运行CI / CD测试。我在构建时遇到错误,并希望控制登录到正在运行的容器以检查环境。
我收到的错误是在角度应用程序中运行“ng test”。 Karma给了我错误:
步骤#1:14 04 2019 12:00:01.869:错误[启动器]:平台上的Chrome浏览器没有二进制文件。 步骤1:请设置“CHROME_BIN”env变量。
所以我希望能够安装到环境中,这样我就可以直观地检查并确定chrome bin的路径。
目前,这里的文档声明我只能查看输出历史记录。
https://cloud.google.com/cloud-build/docs/view-build-results
是否可以控制日志进入谷歌云构建?如果是这样,我如何控制登录谷歌云构建?
谢谢
更新:
感谢您的回复ffd03e。
这是我添加你的bash entypoint后我现在使用的yaml文件,以及云输出。我将查看您发布的链接并进行另一次更新。 (由于chrome ENV是空的,我曾尝试通过ls设置查找)虽然这是使用YAML文件进行调试的唯一方法吗?我希望远程进入云中的bash shell,这样我就不必继续将更改推送到我的存储库来记录某些内容。
下面列出的配置和输出:
steps:
# Install
- name: 'gcr.io/cloud-builders/npm'
args: ['install']
# bash -c | echo $CHROME_ENV - and checking chrome paths
- id: 'print env vars'
name: 'gcr.io/$PROJECT_ID/ng:latest'
entrypoint: 'bash'
args:
- '-c'
- |
echo 'getting env'
env
echo 'NODE_VERSION: ' $$NODE_VERSION
echo 'CHROME_ENV: ' $$CHROME_ENV
# Test - running this in root also runs test for libraries
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'test']
# Build
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'build']
# Deploy
- name: 'gcr.io/$PROJECT_ID/firebase'
args: ['deploy']
Starting Step #1 - "print env vars"
Step #1 - "print env vars": Pulling image: gcr.io/library-master/ng:latest
Step #1 - "print env vars": latest: Pulling from library-master/ng
Step #1 - "print env vars": 4b105072aa89: Already exists
Step #1 - "print env vars": b775667b1fd0: Already exists
Step #1 - "print env vars": 0fe156bcb4b1: Already exists
Step #1 - "print env vars": fb9906355a0f: Already exists
Step #1 - "print env vars": 880a3b83482f: Already exists
Step #1 - "print env vars": 228e101c8671: Already exists
Step #1 - "print env vars": f77ff8405034: Already exists
Step #1 - "print env vars": cd091f7b9743: Already exists
Step #1 - "print env vars": 60af6f0efde7: Pulling fs layer
Step #1 - "print env vars": 60af6f0efde7: Verifying Checksum
Step #1 - "print env vars": 60af6f0efde7: Download complete
Step #1 - "print env vars": 60af6f0efde7: Pull complete
Step #1 - "print env vars": Digest: sha256:2758958b0130229397599ce976ab163e8959ee2d1c4f13143d6c2233d792e79e
Step #1 - "print env vars": Status: Downloaded newer image for gcr.io/library-master/ng:latest
Step #1 - "print env vars": getting env
Step #1 - "print env vars": NODE_VERSION=8.12.0
Step #1 - "print env vars": HOSTNAME=c2dc51ef6be7
Step #1 - "print env vars": PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Step #1 - "print env vars": PWD=/workspace
Step #1 - "print env vars": SHLVL=1
Step #1 - "print env vars": HOME=/builder/home
Step #1 - "print env vars": YARN_VERSION=1.9.4
Step #1 - "print env vars": BUILDER_OUTPUT=/builder/outputs
Step #1 - "print env vars": _=/usr/bin/env
Step #1 - "print env vars": NODE_VERSION: 8.12.0
Step #1 - "print env vars": CHROME_ENV:
Finished Step #1 - "print env vars"
Starting Step #2
Step #2: Already have image (with digest): gcr.io/cloud-builders/npm
Step #2:
Step #2: > [email protected] test /workspace
Step #2: > ng test
Step #2:
Step #2: 17 04 2019 13:32:21.481:WARN [karma]: No captured browser, open http://localhost:9876/
Step #2: 17 04 2019 13:32:21.486:INFO [karma-server]: Karma v3.1.4 server started at http://0.0.0.0:9876/
Step #2: 17 04 2019 13:32:21.487:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
Step #2: 17 04 2019 13:32:21.497:INFO [launcher]: Starting browser Chrome
Step #2: 17 04 2019 13:32:21.498:ERROR [launcher]: No binary for Chrome browser on your platform.
Step #2: Please, set "CHROME_BIN" env variable.
Step #2: 17 04 2019 13:32:27.258:WARN [karma]: No captured browser, open http://localhost:9876/
-----------另一个尝试使用ls找到Chrome ---------
# Using 'ls' to look for chrome..
Step #1 - "print env vars": ls /usr/bin/google-chrome
Step #1 - "print env vars": ls: cannot access /usr/bin/google-chrome: No such file or directory
Step #1 - "print env vars": ls /usr/bin/chromium-browser
Step #1 - "print env vars": ls: cannot access /usr/bin/chromium-browser: No such file or directory
你是在运行ng test
作为构建步骤还是在Dockerfile中运行?查看您的云构建配置会很有帮助。
这是一个打印环境变量的cloudbuild.yaml
示例。如果与ng new my-app
一起使用并使用ng community cloud builder,它也会重现该错误。
# npm install
- id: 'install dependencies'
name: 'gcr.io/cloud-builders/npm'
args: ['install']
# bash -c | echo $CHROME_ENV
- id: 'print env vars'
name: 'gcr.io/$PROJECT_ID/ng:latest'
entrypoint: 'bash'
args:
- '-c'
- |
echo 'getting env'
env
echo 'NODE_VERSION: ' $$NODE_VERSION
echo 'CHROME_ENV: ' $$CHROME_ENV
# ng test
- id: 'run unit tests'
name: 'gcr.io/$PROJECT_ID/ng:latest'
args: ['test']
资源:Substitute Variable Values,Mastering Google Cloud Build Config Syntax
您的测试似乎使用了chrome。从Cloud Build运行时,应使用无头chrome或phantomjs运行测试。您运行ng test
的构建步骤可能没有安装无头chrome。
相关链接