【问题标题】:Running ruby on rails scripts in Jenkinsfile在 Jenkinsfile 中运行 ruby​​ on rails 脚本
【发布时间】:2018-08-08 03:35:48
【问题描述】:

目前我将我的 Gitlab 设置为每当我推送到一个分支时,它都会使用 webhook 在 Jenkins 中触发构建。我在 Jenkins 中使用了一个插件 Multibranch Pipeline,以便构建可以在所有分支上运行。

但我在 Jenkins 中看到您需要将脚本放在 Jenkinsfile 中,但我找不到关于如何运行 ruby​​ 脚本此配置的良好参考。

这些是我需要完成的任务

gem install bundler
bundle install
cp config/database-gitlab.yml config/database.yml
bundle exec rake db:create db:migrate RAILS_ENV=test
bundle exec rake test

如何将这些脚本放入 Jenkinsfile 中

node {
  try {
    stage ('Clone') {
      checkout scm
    }
    stage ('Build') {
      sh "echo 'shell scripts to build project...'"
      sh "echo 'Running ${env.BRANCH_NAME}'"
    }
    stage ('Tests') {
    }
  } catch (err) {
    currentBuild.result = 'FAILED'
      throw err
  }
}

【问题讨论】:

    标签: ruby-on-rails ruby jenkins jenkins-pipeline jenkins-cli


    【解决方案1】:

    您可以将所有脚本放在一个 ruby​​ 文件中并运行如下内容:

    sh 'ruby ./script.rb'
    

    【讨论】:

      【解决方案2】:

      @SatyamSingh 描述的脚本示例如下:

      安装.sh

      gem install bundler
      bundle install
      cp config/database-gitlab.yml config/database.yml
      bundle exec rake db:create db:migrate RAILS_ENV=test
      bundle exec rake test
      

      詹金斯文件

      node {
      ...
          stage ('Clone') {
            checkout scm
          }
          stage ('Build') {
              sh gem install bundler
              sh bundle install
              sh cp config/database-gitlab.yml config/database.yml
              sh bundle exec rake db:create db:migrate RAILS_ENV=test
              sh bundle exec rake test
              ....
          }
          stage ('Tests') {
      ...
          }
      ...
      }
      

      以上两者都应该是您的项目 SCM 存储库的一部分。 Jenkinsfile 在“构建”阶段执行每个 shell 命令。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多