Build and test Ruby apps
This guidance explains how to automatically build Ruby projects.
Follow these instructions to set up a pipeline for a Ruby app.
The code in the following repository is a simple Ruby app. To get started, fork this repo to your GitHub account.
Sign in to your Azure DevOps organization and navigate to your project.
In your project, navigate to the Pipelines page. Then choose the action to create a new pipeline.
Walk through the steps of the wizard by first selecting GitHub as the location of your source code.
You might be redirected to GitHub to sign in. If so, enter your GitHub credentials.
When the list of repositories appears, select your Ruby sample repository.
Azure Pipelines will analyze the code in your repository and recommend
Rubytemplate for your pipeline. Select that template.
Azure Pipelines will generate a YAML file for your pipeline. Select Save and run, then select Commit directly to the master branch, and then choose Save and run again.
A new run is started. Wait for the run to finish.
When you're done, you'll have a working YAML file (
azure-pipelines.yml) in your repository that's ready for you to customize.
To make changes to the YAML file as described in this topic, select the pipeline in the Pipelines page, and then Edit the
You can use Azure Pipelines to build your Ruby projects without needing to set up any infrastructure of your own. Ruby is preinstalled on Microsoft-hosted agents in Azure Pipelines. You can use Linux, macOS, or Windows agents to run your builds.
For the exact versions of Ruby that are preinstalled, refer to Microsoft-hosted agents. To install a specific version of Ruby on Microsoft-hosted agents, add the Use Ruby Version task to the beginning of your pipeline.
Use a specific Ruby version
Add the Use Ruby Version task to set the version of Ruby used in your pipeline. This snippet adds Ruby 2.4 or later to the path and sets subsequent pipeline tasks to use it.
# https://docs.microsoft.com/azure/devops/pipelines/languages/ruby pool: vmImage: 'ubuntu-16.04' # other options: 'macOS-10.13', 'vs2017-win2016' steps: - task: UseRubyVersion@0 inputs: versionSpec: '>= 2.4' addToPath: true
To install Rails, add the following snippet to your
- script: gem install rails && rails -v displayName: 'gem install rails'
To use Bundler to install dependencies, add the following snippet to your
- script: | CALL gem install bundler bundle install --retry=3 --jobs=4 displayName: 'bundle install'
To execute Rake in the context of the current bundle (as defined in your Gemfile), add the following snippet to your
- script: bundle exec rake displayName: 'bundle exec rake'
Publish test results
The sample code includes unit tests written using RSpec. When Rake is run by the previous step, it runs the RSpec tests. The RSpec RakeTask in the Rakefile has been configured to produce JUnit style results using the RspecJUnitFormatter.
Add the Publish Test Results task to publish JUnit style test results to the server. When you do this, you get a rich test reporting experience that can be used for easily troubleshooting any failed tests and for test timing analysis.
- task: PublishTestResults@2 condition: succeededOrFailed() inputs: testResultsFiles: '**/test-*.xml' testRunTitle: 'Ruby tests'
Publish code coverage results
The sample code uses SimpleCov to collect code coverage data when unit tests are run. SimpleCov is configured to use Cobertura and HTML report formatters.
Add the Publish Code Coverage Results task to publish code coverage results to the server. When you do this, coverage metrics can be seen in the build summary and HTML reports can be downloaded for further analysis.
- task: PublishCodeCoverageResults@1 inputs: codeCoverageTool: Cobertura summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml' reportDirectory: '$(System.DefaultWorkingDirectory)/**/coverage'
Build a container image
You can also build and publish a Docker container image for your Ruby app. For more information, see Docker.
Geri bildirim yükleniyor...