【发布时间】:2018-01-29 12:32:09
【问题描述】:
在Microsoft docs 上,它声明您可以为特定的构建任务设置条件。例如,在定义的 Git 分支的特定版本上运行构建。
但是是否也可以仅在提交包含 git-tag 的情况下使 VSTS 构建 NPM 包的条件?
更新 1: 命令$ git describe (source) 似乎是解决方案的一个可能部分。此命令获取最后一个提交哈希并匹配它以查看是否有注释标签。但是,它并不等于我们在 VSTS 的自定义条件中需要的布尔值。
更新 2: 使用 npm git-describe 你可以返回最新的提交是否有注释标签。 gulp 任务示例:
/** Example of a gulp task using git describe */
var gulp = require('gulp');
var {gitDescribeSync} = require('git-describe');
/**
* @function
* @name checkGitTag
* @description Returns wether or not the latest commit has a tag
* @returns {(String|null)} Git tag or null if no git tag exists on the commit
*/
var checkGitTag = function() {
var gitInfo = gitDescribeSync();
// output the result to debug
console.log(gitInfo.tag);
// gitInfo.tag seems to contain the logic needed
};
gulp.task('checkGitTag', checkGitTag);
module.exports = checkGitTag;
也许通过在构建服务器上安装 NPM 包并使用类似的功能可以工作。要去测试一下。
【问题讨论】:
标签: node.js git continuous-integration azure-devops