如何使用 Jenkins 在 CI 中的 Cypres 仪表板中填充作者、分支、提交、消息?

Man*_*cal 2 javascript continuous-integration github jenkins cypress

我正在尝试获取Cypress 仪表板中的提交信息详细信息中的提交信息详细信息。我还没有能够完成,但我已经取得了一些进步......

我将描述到目前为止我所做的事情:

npm install --save @cypress/commit-info

  • 将插件导入到plugin/index.js文件中,如下所示:
const { commitInfo } = require('@cypress/commit-info');

module.exports = on => {
  on('file:preprocessor', file => {
    commitInfo().then(console.log);
  });
};
Run Code Online (Sandbox Code Playgroud)

现在,我在终端中获取了所有信息:作者、分支、提交和消息!:) 但是,我仍然没有链接到我的赛普拉斯仪表板的信息详细信息。

这是我目前得到的:

下一步是什么?该文档对我来说不清楚......

Bre*_*dan 5

在我们的例子中,我们在 docker 容器内运行所有内容。我们将代码复制到容器中,但不复制 .git 目录,它很大,耗时,而且我们不需要它。 @cypress/commit-info 假设有一个 .git 目录,所以因为没有,所以它不起作用。

我们通过在 cypress run 命令中明确设置cypress 期望的值Jenkinsfile来克服这个问题:

def commitMessage = sh(script:"git log --format=%B -n 1 ${env.GIT_COMMIT}", returnStdout:true).trim()
def commitAuthor = sh(script:"git log --format='%an' -n 1 ${env.GIT_COMMIT}", returnStdout:true).trim()
def commitEmail = sh(script:"git log --format='%ae' -n 1 ${env.GIT_COMMIT}", returnStdout:true).trim()

def cypressVars = "COMMIT_INFO_BRANCH=${env.GIT_BRANCH} COMMIT_INFO_SHA=${env.GIT_COMMIT} COMMIT_INFO_REMOTE=${env.GIT_URL} COMMIT_INFO_MESSAGE=\"${commitMessage}\" COMMIT_INFO_AUTHOR=\"${commitAuthor}\" COMMIT_INFO_EMAIL=${commitEmail}"

// call cypress however you do and include cypressVars as part of the command
Run Code Online (Sandbox Code Playgroud)