2017-08-23 54 views
0

在我的測試設置中,我使用docker執行程序來運行我的構建版本。幾乎我們所有的項目都是在官方節點圖片上運行的(即node:6)。將環境變量從Gitlab docker執行程序傳遞到圖像

默認情況下,這些官方圖像的日誌記錄級別設置爲輸出相當高。

根據官方文檔,可以禁用https://github.com/nodejs/docker-node/blob/master/README.md#verbosity

Verbosity 

By default the Node.js Docker Image has npm log verbosity set to info instead 
of the default warn. This is because of the way Docker is isolated from the 
host operating system and you are not guaranteed to be able to retrieve the 
npm-debug.log file when npm fails. 

When npm fails, it writes it's verbose log to a log file inside the container. 
If npm fails during an install when building a Docker Image with the docker 
build command, this log file will become inaccessible when Docker exits. 

The Docker Working Group have chosen to be overly verbose during a build to 
provide an easy audit trail when install fails. If you prefer npm to be less 
verbose you can easily reset the verbosity of npm using the following 
techniques: 

Dockerfile 

If you create your own Dockerfile which inherits from the node image you can 
simply use ENV to override NPM_CONFIG_LOGLEVEL. 

FROM node 
ENV NPM_CONFIG_LOGLEVEL warn 
... 

Docker Run 

If you run the node image using docker run you can use the -e flag to override 
NPM_CONFIG_LOGLEVEL. 

$ docker run -e NPM_CONFIG_LOGLEVEL=warn node ... 

NPM run 

If you are running npm commands you can use --loglevel to control the 
verbosity of the output. 

$ docker run node npm --loglevel=warn ... 

但是,當我剛剛從我的gitlab-ci.yml文件中引用泊塢窗圖像,像這樣:

image: node:6 

test: 
    script: 
     - npm install 

我怎樣才能通過環境變量,設置日誌級別,我的碼頭執行?

回答

1

gitlab-ci reference中所列,您可以使用variables關鍵字在配置文件中指定環境變量。在你的情況,這將是

image: node:6 

test: 
    variables: 
     NPM_CONFIG_LOGLEVEL: warn 
    script: 
     - npm install 

另外,您可以在您的CI配置的腳本部分添加--loglevel=warn所有node命令。

相關問題