Add support for deployment groups (#31)
* Add deployment groups support. Feature #27
This commit is contained in:
Родитель
a5dab42b7b
Коммит
1fbedb20f6
|
@ -94,6 +94,8 @@ suites:
|
|||
vsts_url: <%= ENV['VSTS_URL'] %>
|
||||
vsts_pool: <%= ENV['VSTS_POOL'] %>
|
||||
vsts_token: <%= ENV['VSTS_TOKEN'] %>
|
||||
deployment_group_name: <%= ENV['VSTS_DEPLOYMENT_GROUP_NAME'] %>
|
||||
deployment_group_project: <%= ENV['VSTS_DEPLOYMENT_GROUP_PROJECT'] %>
|
||||
|
||||
- name: linux-basic
|
||||
run_list:
|
||||
|
@ -112,6 +114,8 @@ suites:
|
|||
vsts_url: <%= ENV['VSTS_URL'] %>
|
||||
vsts_pool: <%= ENV['VSTS_POOL'] %>
|
||||
vsts_token: <%= ENV['VSTS_TOKEN'] %>
|
||||
deployment_group_name: <%= ENV['VSTS_DEPLOYMENT_GROUP_NAME'] %>
|
||||
deployment_group_project: <%= ENV['VSTS_DEPLOYMENT_GROUP_PROJECT'] %>
|
||||
|
||||
- name: osx-basic
|
||||
run_list:
|
||||
|
|
34
README.md
34
README.md
|
@ -41,14 +41,19 @@ This resource installs and configures the vsts build and release agent
|
|||
- `:restart`: Restart the agent service
|
||||
|
||||
#### Parameters
|
||||
- `agent_name`: Name attribute. The name of the vsts agent
|
||||
- `agent_name`: name attribute. The name of the vsts agent
|
||||
- `deploymentGroup`: deploy the agent into the [deployment group](https://docs.microsoft.com/en-us/vsts/pipelines/release/deployment-groups/?view=vsts). Default '`false`'
|
||||
* `deploymentGroupName`: name of the deployment group. Only applies if `deploymentGroup==true`
|
||||
* `projectName`: name of the vsts/tfs project where to deploy the agent. Only applies if `deploymentGroup==true`
|
||||
* `collectionName`: name of the vsts/tfs collection where to deploy the agent. Only applies if `deploymentGroup==true`. Dafault value is `DefaultCollection`
|
||||
* `deploymentGroupTags`: a comma-separated list of tags to set for the agent. Only applies if `deploymentGroup==true`
|
||||
- `version`: an agent version to install. Default version from an attribute
|
||||
- `install_dir`: A target directory to install the vsts agent
|
||||
- `path`: Overwrite system PATH environment variable values. Linux and macOS only
|
||||
- `env`: Additional environment variables. Linux and macOS only
|
||||
- `user`: Set a local user to run the vsts agent
|
||||
- `group`: Set a local group to run the vsts agent
|
||||
- `runasservice`: run agent as a service. Default 'true'
|
||||
- `runasservice`: run agent as a service. Default '`true`'
|
||||
- `windowslogonaccount`: Set a user name to run a windows service. Possible values are "NT AUTHORITY\NetworkService", "NT AUTHORITY\LocalService" or any system valid username
|
||||
- `windowslogonpassword`: Set password for windowslogonaccount unless it is equal to NetworkService or LocalService
|
||||
- `vsts_url`: url to VSTS instance
|
||||
|
@ -64,7 +69,7 @@ This resource installs and configures the vsts build and release agent
|
|||
- `work_folder`: Set different workspace location. Default is "install_dir/\_work"
|
||||
|
||||
#### Examples
|
||||
Install, configure, restart and remove an agent.
|
||||
Install, configure, restart and remove a build agent.
|
||||
Check [windows](test/cookbooks/windows-basic/recipes/default.rb), [linux](test/cookbooks/linux-basic/recipes/default.rb) or [osx](test/cookbooks/osx-basic/recipes/default.rb) tests for more examples.
|
||||
|
||||
```ruby
|
||||
|
@ -100,5 +105,28 @@ vsts_agent 'agent_01' do
|
|||
end
|
||||
```
|
||||
|
||||
Install, configure, restart and remove a deployment agent.
|
||||
|
||||
```ruby
|
||||
vsts_agent 'deployment_agent_01' do
|
||||
install_dir dir
|
||||
deploymentGroup true
|
||||
deploymentGroupName 'project1-deployment-group'
|
||||
projectName 'project1'
|
||||
collectionName 'DefaultCollection'
|
||||
deploymentGroupTags "web, db"
|
||||
user 'vagrant'
|
||||
group 'vagrant'
|
||||
path '/usr/local/bin/:/usr/bin:/opt/bin/' # only works on nix systems
|
||||
env('M2_HOME' => '/opt/maven', 'JAVA_HOME' => '/opt/java') # only works on nix systems
|
||||
vsts_url 'https://contoso.visualstudio.com'
|
||||
vsts_token 'my_secret_token_from_vsts'
|
||||
windowslogonaccount 'builder' # will be used only on windows
|
||||
windowslogonpassword 'Pas$w0r_d' # will be used only on windows
|
||||
action :install
|
||||
end
|
||||
|
||||
```
|
||||
|
||||
# How to contribute
|
||||
Check [Contribution Guide](CONTRIBUTING.md) and [Testing Guide](TESTING.md)
|
||||
|
|
|
@ -30,6 +30,8 @@ set VSTS_URL='https://account.visualstudio.com'
|
|||
set VSTS_POOL=default
|
||||
set VSTS_USER=username
|
||||
set VSTS_TOKEN=my_secret_token_from_vsts
|
||||
set VSTS_DEPLOYMENT_GROUP_NAME=test-chef-deployment
|
||||
set VSTS_DEPLOYMENT_GROUP_PROJECT=test
|
||||
```
|
||||
Linux / Mac:
|
||||
```
|
||||
|
@ -37,6 +39,8 @@ export VSTS_URL='https://account.visualstudio.com'
|
|||
export VSTS_POOL=default
|
||||
export VSTS_USER=username
|
||||
export VSTS_TOKEN=my_secret_token_from_vsts
|
||||
export VSTS_DEPLOYMENT_GROUP_NAME=test-chef-deployment
|
||||
export VSTS_DEPLOYMENT_GROUP_PROJECT=test
|
||||
```
|
||||
|
||||
If the username of the box you're testing differs from standard "vagrant":
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
default['vsts_agent']['binary']['version'] = '2.126.0'
|
||||
default['vsts_agent']['binary']['version'] = '2.136.1'
|
||||
|
||||
case node['platform_family']
|
||||
when 'windows'
|
||||
|
|
|
@ -7,7 +7,7 @@ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
|||
source_url 'https://github.com/Microsoft/vsts-agent-cookbook' if respond_to?(:source_url)
|
||||
issues_url 'https://github.com/Microsoft/vsts-agent-cookbook/issues' if respond_to?(:issues_url)
|
||||
chef_version '>= 12.4' if respond_to?(:chef_version)
|
||||
version '2.0.4'
|
||||
version '3.0.0'
|
||||
|
||||
%w(ubuntu debian redhat centos mac_os_x windows).each do |operating_system|
|
||||
supports operating_system
|
||||
|
|
|
@ -27,6 +27,13 @@ property :vsts_username, String, desired_state: false
|
|||
property :vsts_password, String, sensitive: true, desired_state: false
|
||||
property :vsts_token, String, sensitive: true, desired_state: false
|
||||
|
||||
# Deployment Groups
|
||||
property :deploymentGroup, [TrueClass, FalseClass], default: false
|
||||
property :deploymentGroupName, String
|
||||
property :deploymentGroupTags, String, desired_state: false
|
||||
property :projectName, String
|
||||
property :collectionName, String, default: 'DefaultCollection'
|
||||
|
||||
include ::VSTS::Agent::Helpers
|
||||
|
||||
load_current_value do
|
||||
|
@ -40,6 +47,10 @@ load_current_value do
|
|||
vsts_url state['vsts_url']
|
||||
vsts_pool state['vsts_pool']
|
||||
work_folder state['work_folder']
|
||||
deploymentGroup state['deploymentGroup']
|
||||
deploymentGroupName state['deploymentGroupName']
|
||||
projectName state['projectName']
|
||||
collectionName state['collectionName']
|
||||
|
||||
runasservice service_exist?(install_dir)
|
||||
end
|
||||
|
@ -97,11 +108,22 @@ action :install do
|
|||
unattended: nil,
|
||||
replace: nil,
|
||||
url: new_resource.vsts_url,
|
||||
pool: new_resource.vsts_pool,
|
||||
agent: new_resource.agent_name,
|
||||
work: new_resource.work_folder,
|
||||
}
|
||||
|
||||
if new_resource.deploymentGroup
|
||||
args[:deploymentGroup] = nil
|
||||
args[:deploymentGroupName] = new_resource.deploymentGroupName || new_resource.vsts_pool
|
||||
args[:projectName] = new_resource.projectName
|
||||
args[:collectionName] = new_resource.collectionName if new_resource.collectionName
|
||||
|
||||
args[:addDeploymentGroupTags] = nil if new_resource.deploymentGroupTags
|
||||
args[:deploymentGroupTags] = new_resource.deploymentGroupTags if new_resource.deploymentGroupTags
|
||||
else
|
||||
args[:pool] = new_resource.vsts_pool
|
||||
end
|
||||
|
||||
if new_resource.runasservice
|
||||
args[:runasservice] = nil
|
||||
args[:windowslogonaccount] = new_resource.windowslogonaccount if windows?
|
||||
|
@ -149,7 +171,11 @@ action :install do
|
|||
group: new_resource.group,
|
||||
vsts_url: new_resource.vsts_url,
|
||||
vsts_pool: new_resource.vsts_pool,
|
||||
work_folder: new_resource.work_folder)
|
||||
work_folder: new_resource.work_folder,
|
||||
deploymentGroup: new_resource.deploymentGroup,
|
||||
deploymentGroupName: new_resource.deploymentGroupName,
|
||||
projectName: new_resource.projectName,
|
||||
collectionName: new_resource.collectionName)
|
||||
Chef::Log.info "'#{new_resource.agent_name}' agent was installed"
|
||||
end
|
||||
action :run
|
||||
|
|
|
@ -2,4 +2,6 @@
|
|||
default['vsts_agent_test']['vsts_url'] = nil
|
||||
default['vsts_agent_test']['vsts_pool'] = nil
|
||||
default['vsts_agent_test']['vsts_token'] = nil
|
||||
default['vsts_agent_test']['deployment_group_name'] = nil
|
||||
default['vsts_agent_test']['deployment_group_project'] = nil
|
||||
default['vsts_agent_test']['username'] = 'vagrant'
|
||||
|
|
|
@ -23,6 +23,7 @@ include_recipe 'vsts_agent::default'
|
|||
|
||||
agent1_name = "#{node['hostname']}_01"
|
||||
agent2_name = "#{node['hostname']}_02"
|
||||
agent3_name = "#{node['hostname']}_deployment_03"
|
||||
|
||||
agents_dir = '/opt/agents'
|
||||
|
||||
|
@ -37,6 +38,11 @@ vsts_agent agent2_name do
|
|||
action :remove
|
||||
end
|
||||
|
||||
vsts_agent agent3_name do
|
||||
vsts_token node['vsts_agent_test']['vsts_token']
|
||||
action :remove
|
||||
end
|
||||
|
||||
log 'Test notification' do
|
||||
action :nothing
|
||||
end
|
||||
|
@ -79,3 +85,24 @@ end
|
|||
vsts_agent agent2_name do
|
||||
action :restart
|
||||
end
|
||||
|
||||
# Agent 3 deployment group
|
||||
vsts_agent agent3_name do
|
||||
deploymentGroup true
|
||||
deploymentGroupName node['vsts_agent_test']['deployment_group_name']
|
||||
projectName node['vsts_agent_test']['deployment_group_project']
|
||||
deploymentGroupTags 'web, db'
|
||||
install_dir "#{agents_dir}/#{agent3_name}"
|
||||
user 'builder'
|
||||
group 'builder'
|
||||
path '/usr/local/bin/:/usr/bin:/opt/bin/:/tmp/'
|
||||
env('M2_HOME' => '/opt/maven', 'JAVA_HOME' => '/opt/java')
|
||||
vsts_url node['vsts_agent_test']['vsts_url']
|
||||
vsts_token node['vsts_agent_test']['vsts_token']
|
||||
work_folder '/tmp/work'
|
||||
action :install
|
||||
end
|
||||
|
||||
vsts_agent agent3_name do
|
||||
action :restart
|
||||
end
|
||||
|
|
|
@ -15,6 +15,7 @@ include_recipe 'vsts_agent::default'
|
|||
|
||||
agent1_name = "win_#{node['hostname']}_01"
|
||||
agent2_name = "win_#{node['hostname']}_02"
|
||||
agent3_name = "win_#{node['hostname']}_deployment_03"
|
||||
|
||||
agents_dir = 'C:\\agents'
|
||||
|
||||
|
@ -33,6 +34,11 @@ vsts_agent agent2_name do
|
|||
action :remove
|
||||
end
|
||||
|
||||
vsts_agent agent3_name do
|
||||
vsts_token node['vsts_agent_test']['vsts_token']
|
||||
action :remove
|
||||
end
|
||||
|
||||
# Agent1
|
||||
vsts_agent agent1_name do
|
||||
install_dir "#{agents_dir}\\#{agent1_name}"
|
||||
|
@ -70,3 +76,22 @@ end
|
|||
vsts_agent agent2_name do
|
||||
action :restart
|
||||
end
|
||||
|
||||
# Agent3
|
||||
vsts_agent agent3_name do
|
||||
deploymentGroup true
|
||||
deploymentGroupName node['vsts_agent_test']['deployment_group_name']
|
||||
projectName node['vsts_agent_test']['deployment_group_project']
|
||||
deploymentGroupTags 'web, db'
|
||||
install_dir "#{agents_dir}\\#{agent2_name}"
|
||||
user 'builder'
|
||||
vsts_url node['vsts_agent_test']['vsts_url']
|
||||
vsts_pool node['vsts_agent_test']['vsts_pool']
|
||||
vsts_token node['vsts_agent_test']['vsts_token']
|
||||
windowslogonaccount 'NT AUTHORITY\\NetworkService'
|
||||
action :install
|
||||
end
|
||||
|
||||
vsts_agent agent3_name do
|
||||
action :restart
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче