... 添加到 coderanger,如果您想根据 CI 工具是否设置环境变量来选择驱动程序或选项,您还可以执行以下操作:
---
<%
#--------------------------------------------------------------------------
# the driver_plugin can be overridden with an environment variable:
# $ KITCHEN_DRIVER=docker kitchen test
# if not specified, defaults are used...
# - kitchen_driver_ci if environment variable CI=true or TRAVIS=true are present
# - kitchen_driver_local is used otherwise (which defaults to vagrant)
#--------------------------------------------------------------------------
kitchen_driver_ci = 'ec2'
kitchen_driver_local = 'vagrant'
kitchen_driver_default = kitchen_driver_local
if ENV['KITCHEN_DRIVER']
kitchen_driver = ENV['KITCHEN_DRIVER']
elsif ENV['TRAVIS']=="true"
kitchen_driver = kitchen_driver_ci
elsif ENV['CI']=="true"
kitchen_driver = kitchen_driver_ci
else
kitchen_driver = kitchen_driver_default
end
puts "-----> driver_plugin: #{kitchen_driver.to_s}"
%>
driver_plugin: <%= kitchen_driver %>
driver_config:
require_chef_omnibus: 11.10.4
<% if kitchen_driver == 'ec2' %>
aws_access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
aws_secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
aws_ssh_key_id: <%= ENV['AWS_SSH_KEY_ID'] || "test-kitchen" %>
ssh_key: <%= ENV['AWS_SSH_KEY_FILE'] || "./test-kitchen.pem" %>
region: <%= ENV['AWS_REGION'] || "us-east-1" %>
availability_zone: <%= ENV['AWS_AVAILABILITY_ZONE'] || "us-east-1c" %>
flavor_id: "t2.small"
groups: ["test-kitchen"]
<% end %>
<% if kitchen_driver == 'vagrant' %>
customize:
memory: 2048
<% end %>
platforms:
- name: ubuntu-14.04
<% if kitchen_driver == 'ec2' %>
driver_config:
image_id: ami-6ab2a702
username: ubuntu
tags: { "Name": "Test Kitchen" }
<% end %>
busser:
sudo: true
suites:
- name: default
run_list: [
]
attributes: {
}
这样您就可以维护一个文件并避免不同的平台测试(在一个文件中进行更改而忘记在另一个文件中进行更改)。在某些情况下,.kitchen.local.yml 中提供的选项可能与 .kitchen.yml 中的选项冲突。