如何从位桶管道中推入git ?

时间:2021-08-24 16:27:09

I have a node project. What I want to do is on a developer checkin (commit and push), I want to run the bitbucket pipeline which would internally do the following

我有一个节点项目。我想做的是在开发人员签入(提交和推送)时,我想运行bitbucket管道,它将在内部执行以下操作

  1. npm install and npm test
  2. npm安装和npm测试
  3. npm version patch (to increment the version in the package.json)
  4. npm版本补丁(增加package.json中的版本)
  5. git push origin master --follow-tags
  6. git push origin master—follow-tags
  7. npm publish
  8. npm发布

bitbucket-pipelines.yml

bitbucket-pipelines.yml

    image: node:8
    pipelines:
      default:
        - step:
            caches:
              - node
            script:
              - npm version patch
              - git push origin develop --follow-tags
              - npm publish

I am facing problem on the "git push origin master --follow-tags". How do I give pipeline the permission to push back to the repository?

我正面临着“git推源母版——跟随标签”的问题。如何允许管道返回到存储库?

Also I want to know if this will trigger a cycle, where my bitbucket pipeline executes again since I incremented the package.json version and did a check in (commit and push)?

我还想知道这是否会触发一个循环,在这个循环中,我的bitbucket管道再次执行,因为我增加了包的数量。json版本并进行了检入(提交和推送)?

What is the recommended way of doing CI/CD With version number increments on a nodejs project using bitbucket-pipelines?

使用位嵌套管道在nodejs项目上使用版本号递增进行CI/CD的推荐方式是什么?

Cheers, Rohit

欢呼,罗希特

1 个解决方案

#1


2  

I was facing a similar problem, though not associated with nodejs development.

我也遇到了类似的问题,尽管与nodejs开发无关。

The reason a build fails on git push is that ssh key pair that you are able to generate under Pipelines > SSH keys settings doesn't have write access.

在git push上构建失败的原因是可以在管道>下生成的ssh密钥对没有写访问权限。

Delete generated pair and use your own that is connected to your account. You also have to create a commit before the push. Add to your bitbucket-pipelines.yml:

删除生成的对,并使用您自己的连接到您的帐户。您还必须在推送之前创建一个提交。添加到您的bitbucket-pipelines.yml:

- git config user.email <your@email>
- git add package.json
- git commit -m "updated version"

The answer to your second question is: yes, it would trigger another build, as they are triggered on every commit by default. In my case, subsequent build produced the exact same output which made the whole build failed on git commit. It was up-to-date with origin, therefore stopped repetitive triggering.

第二个问题的答案是:是的,它将触发另一个构建,因为默认情况下,每个提交都会触发它们。在我的例子中,后续构建产生了完全相同的输出,这使得整个构建在git commit上失败。这是最新的起源,因此停止重复触发。

It's not nice to have two builds on every change where one of them always fails. A solution to this might be running builds by hand by adding the custom section into config.

在每个变更上都有两个构建是不好的,其中一个总是失败。解决这个问题的方法可能是通过将自定义部分添加到config中来手工运行构建。

Eventually, I abandoned this whole idea pushing back something with pipelines, because of lack of automation.

最终,由于缺乏自动化,我放弃了这个想法,用管道把东西往后推。

Updated

Now, there is also a possibility to schedule builds. With this feature, repetitive triggering could be also avoided.

现在,还有一种安排构建的可能性。有了这个特性,重复触发也可以避免。

#1


2  

I was facing a similar problem, though not associated with nodejs development.

我也遇到了类似的问题,尽管与nodejs开发无关。

The reason a build fails on git push is that ssh key pair that you are able to generate under Pipelines > SSH keys settings doesn't have write access.

在git push上构建失败的原因是可以在管道>下生成的ssh密钥对没有写访问权限。

Delete generated pair and use your own that is connected to your account. You also have to create a commit before the push. Add to your bitbucket-pipelines.yml:

删除生成的对,并使用您自己的连接到您的帐户。您还必须在推送之前创建一个提交。添加到您的bitbucket-pipelines.yml:

- git config user.email <your@email>
- git add package.json
- git commit -m "updated version"

The answer to your second question is: yes, it would trigger another build, as they are triggered on every commit by default. In my case, subsequent build produced the exact same output which made the whole build failed on git commit. It was up-to-date with origin, therefore stopped repetitive triggering.

第二个问题的答案是:是的,它将触发另一个构建,因为默认情况下,每个提交都会触发它们。在我的例子中,后续构建产生了完全相同的输出,这使得整个构建在git commit上失败。这是最新的起源,因此停止重复触发。

It's not nice to have two builds on every change where one of them always fails. A solution to this might be running builds by hand by adding the custom section into config.

在每个变更上都有两个构建是不好的,其中一个总是失败。解决这个问题的方法可能是通过将自定义部分添加到config中来手工运行构建。

Eventually, I abandoned this whole idea pushing back something with pipelines, because of lack of automation.

最终,由于缺乏自动化,我放弃了这个想法,用管道把东西往后推。

Updated

Now, there is also a possibility to schedule builds. With this feature, repetitive triggering could be also avoided.

现在,还有一种安排构建的可能性。有了这个特性,重复触发也可以避免。