Skip to content

execute knife

Stuart Preston edited this page May 2, 2018 · 2 revisions

Execute Knife

Runs the specified knife command with specific options.

This task allows the resue of the Chef Server endpoint so that the same credentials can be used.

Settings

The following settings are available on this task:

Setting Group Required Default Value Description
Display name Yes Install Gem Display name of the task. Will be displayed in the pipeline
Chef Server Endpoint No The endpoint to use to get the URL, username and private key
Knife Arguments No The command and arguments that need to be run by knife
Private Key No False State if the private key from the specified endpoint should be save to a file and appended to the arguments
Delete Private Key Advanced No True Remove the private key from the agent after completion
Execute Knife

Information

To be able to accomodate different plugins, this task expects the necessary options to be given as arguments. To aid in this, and to allow the use of the credentials in the command, a few replacement tokens are available that can be used in the arguments text box.

For example in the above screenshot the arguments has been specified as:

cookbook site share -m {URL}

The {URL} token will be replaced with the URL that is specified in the chosen endpoint for the task.

So if the URL was https://supermarket.example.com, then the resultant command would be:

cookbook site share -m https://supermarket.example.com

The tokens that are available are:

Token Description
{URL} URL of the specified endpoint. Does not have to be a Chef server
{USERNAME} Username as specified in the endpoint
{PASSWORD} The password (or client key) as specified in the endpoint.

The only option that cannot be specified on the knife command line is the ability to disable SSL verification. To do this the task will create a temporary knife configuration file with ssl_verify_mode :verify_none as the content. It will then append the -c option to the command. Thus using the above example the command would now look like:

cookbook site share -m https://supermarket.example.com --config /tmp/knife.rb

NOTE: On Windows the path to the knife.rb file will be c:\Windows\temp\knife.rb.

If the private key is required for the knife command then the option 'Private Key' should be selected on the task. This will write out the key to a temporary file and append the correct option to the command. Thus if this was set it would be:

cookbook site share -m https://supermarket.example.com --config /tmp/knife.rb --key /tmp/vsts-task.pem

NOTE: On Windows the path to the key file will be c:\Windows\temp\vsts-task.pem.

Further Example usages

"knife arguments" to use knife to download data bags to your build agent using the admin user from the Chef Server endpoint:

download /data_bags --chef-repo-path $(Build.SourcesDirectory) -u {USERNAME} -s {URL}
Clone this wiki locally