我正在尝试实施GitLab CI Pipelines来构建和部署Angular应用程序.在我们的项目中,我们有两个一般分支:( master仅限生产)和develop.为了开发,我们feature/some-feature从develop分支创建分支.当开发完成后,我们创建合并请求feature/some-feature到develop.当合并请求被批准并合并到develop分支时,我想运行管道以构建应用程序并在某些环境中部署构建.
我在.gitlab-ci.yml中使用以下设置:
image: node:7.5-configured
stages:
- build
- deploy
build_job:
stage: build
only:
- develop
script:
- /bin/bash <some script here>
...
Run Code Online (Sandbox Code Playgroud)
问题是每次我进入任何feature/some-feature分支时都会执行Pipeline .我的设置有什么问题?我怎样才能迫使管道被执行只有当推进行到develop直接分支?
解决方案
这是我的错误 - 我在develop分支和feature/some-feature分支中有两个不同的.gitlab-ci.yml文件.
我在本地安装了Node.js v8.10.0.我写了一个简单的脚本来玩'this':
var x = 1;
var fn = function (a) {
var x = a;
console.log(`local x = ${x}`);
console.log(`global x = ${this.x}`);
}
fn(10);
Run Code Online (Sandbox Code Playgroud)
当我通过Node.js执行脚本时,我得到以下结果:
local x = 10
global x = undefined
Run Code Online (Sandbox Code Playgroud)
当我在Chrome中执行脚本时,我得到以下结果:
local x = 10
global x = 1
Run Code Online (Sandbox Code Playgroud)
您能否向我解释一下,为什么Node.js在全局范围内没有看到x?