Visual Studio Team Services Build Agent Chef Cookbook
Clone or download
estenrye and ivadim Feature/resolve issue 32 (#33)
* remove require of chef/mixin/language

This mixin was removed from chef 14.*
See [this stackoverflow](https://stackoverflow.com/questions/49909084/cannot-load-such-file-chef-mixin-language)

Fixes Recipe Compile error in Chef 14.3.37:

```
       ================================================================================
       Recipe Compile Error in /tmp/kitchen/cache/cookbooks/vsts_agent/libraries/service.rb
       ================================================================================

       LoadError
       ---------
       cannot load such file -- chef/mixin/language

       Cookbook Trace:
       ---------------
         /tmp/kitchen/cache/cookbooks/vsts_agent/libraries/service.rb:4:in `<top (required)>'

       Relevant File Content:
       ----------------------
       /tmp/kitchen/cache/cookbooks/vsts_agent/libraries/service.rb:

         1:  require 'chef/resource/lwrp_base'
         2:  require 'chef/provider/lwrp_base'
         3:  require 'chef/mixin/shell_out'
         4>> require 'chef/mixin/language'
         5:
         6:  module VSTS
         7:    module Agent
         8:      # The service operations for vsts_agent
         9:      class Service
        10:        include Windows::Helper
        11:        include VSTS::Agent::Helpers
        12:        include Chef::DSL::PlatformIntrospection
        13:

       System Info:
       ------------
       chef_version=14.3.37
       platform=debian
       platform_version=8.11
       ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
       program_name=/opt/chef/bin/chef-client
       executable=/opt/chef/bin/chef-client

       Running handlers:
       [2018-08-17T17:57:39-07:00] ERROR: Running exception handlers
       [2018-08-17T17:57:39-07:00] ERROR: Running exception handlers
       Running handlers complete
       [2018-08-17T17:57:39-07:00] ERROR: Exception handlers complete
       [2018-08-17T17:57:39-07:00] ERROR: Exception handlers complete
       Chef Client failed. 0 resources updated in 01 seconds
       [2018-08-17T17:57:39-07:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2018-08-17T17:57:39-07:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2018-08-17T17:57:39-07:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2018-08-17T17:57:39-07:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2018-08-17T17:57:39-07:00] FATAL: LoadError: cannot load such file -- chef/mixin/language
       [2018-08-17T17:57:39-07:00] FATAL: LoadError: cannot load such file -- chef/mixin/language
```

#32

* Fix inability to find default recipe

For some reason the default recipe for build-essential isn't being deployed in 8.1.1.

I haven't figured out why.  Since the logic in that recipe is only 3 lines
long, I opted for using the resource rather than the recipe.

#32

* Fix syntax error that prvents convergence in chef 14.

The variable name and the method were conflicting with each other,
making the compiler not find the helper method.

#32

* Use >= instead of ~> syntax.

* Add missing installation of seven zip.

#32

* Copy win_friendly_path method to helpers library.

For some reason, I wasn't able to get the Windows::Helper library to successfully include itself.
Since the method was simple enough, and unlikely to change much, I felt
moving it into the helpers library made sense, in addition to fixing the issue.

#32

* Revert changes to linux cookbook.

Turns out I had a corupted berkshelf download.  Learning has occurred.
Inspect .bershelf on your dev box before assuming something is broken.

#32

* Add Windows Server 2016 to kitchen.yml

Add Windows Server 2016 with latest chef client to ensure changes work with latest chef.

* Re-add changes after merging latest upstream master.

* Uptick version for bug fix.

#32

* Update solution to utilize feedback provided by @ivadim.

Adds missing include statement.

#33

* Fix linting issues found in CI pipeline.

#32
Latest commit 9c763f1 Sep 30, 2018

README.md

Visual Studio Team Services Build and Release Agent Cookbook

Join the chat at https://gitter.im/Microsoft/vsts-agent-cookbook Build Status Cookbook Version

Installs and configures Visual Studio Team Services Build and Release Agent

Please check Wiki for more examples

Requirements

  • Chef 12.5.0 or higher

Platforms

The following platforms are tested and supported:

  • Debian 8 x64 (Jessie)
  • Debian 9 x64 (Stretch)
  • Ubuntu 16.04 (Xenial Xerus)
  • Ubuntu 17.10 (Artful Aardvark)
  • CentOS 7
  • Windows 10
  • Windows Server 2012 R2
  • OS X 10.10.5
  • OS X 10.11.4

Attributes

  • node['vsts_agent']['binary']['version'] - set version of package to install
  • node['vsts_agent']['prerequisites']['redhat']['install'] - control dependencies installation for redhat based distros(redhat, centos etc.) . Default true
  • node['vsts_agent']['prerequisites']['debian']['install'] - control dependencies installation for debian based distros(debian, ubuntu etc.). Default true

Resource/Provider

vsts_agent

This resource installs and configures the vsts build and release agent

Actions

  • :install: Install and configure the agent
  • :remove: Remove the agent and unregister it from VSTS
  • :restart: Restart the agent service

Parameters

  • agent_name: name attribute. The name of the vsts agent
  • deploymentGroup: deploy the agent into the deployment group. 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'
  • 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
  • vsts_pool: A pool to connect an agent
  • vsts_auth: Authentication type. Default PAT auth. Valid options are:
    • PAT - Personal Access Token (requires vsts_token),
    • Negotiate - Kerberos or NTLM (requires vsts_username and vsts_password),
    • ALT - Alternate Credentials (requires vsts_username and vsts_password),
    • Integrated - Windows default credentials (doesn't require any credentials).
  • vsts_token: A personal access token for VSTS. Used with PAT auth type. See
  • vsts_username: A user to connect to VSTS. Used with Negotiate and ALT auth
  • vsts_password: A user to connect to VSTS. Used with Negotiate and ALT auth
  • work_folder: Set different workspace location. Default is "install_dir/_work"

Examples

Install, configure, restart and remove a build agent. Check windows, linux or osx tests for more examples.

include_recipe 'vsts_agent::default'

if platform_family?('windows')
  dir = 'c:\\agents'
else
  dir = '/tmp/agents'
end

vsts_agent 'agent_01' do
  install_dir dir
  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_pool 'default'
  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

vsts_agent 'agent_01' do
  action :restart
end

vsts_agent 'agent_01' do
  vsts_token 'my_secret_token_from_vsts'
  action :remove
end

Install, configure, restart and remove a deployment agent.

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 and Testing Guide