-
Notifications
You must be signed in to change notification settings - Fork 5
/
steps_cookbook_uploaded_check.yml
39 lines (31 loc) · 1.34 KB
/
steps_cookbook_uploaded_check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
steps:
- template: steps_knife_config.yml@pipeline_templates
- task: CmdLine@2
displayName: 'Write Cookbook Uploaded Check Script'
inputs:
script: |
cat << EOF > $(Agent.TempDirectory)/cookbook_uploaded_check.rb
#!/bin/env ruby
require 'chef/cookbook/metadata'
require 'json'
metadata = Chef::Cookbook::Metadata.new
metadata.from_file('metadata.rb')
cookbook = metadata.name
version = metadata.version
Chef::Log.info "Checking cookbook #{cookbook} version #{version}"
cookbooks = api.get('cookbooks?num_versions=all')
if cookbooks[cookbook].nil?
Chef::Log.info "Cookbook #{cookbook} does not exist on the Chef Infra Server."
return # No need to proceed, cookbook hasn't been uploaded before
end
unless cookbooks[cookbook]['versions'].select { |c| c['version'] == version }.empty?
Chef::Log.error cookbooks[cookbook]['versions']
raise "Cookbook #{cookbook} version #{version} exists on the Chef Infra Server!"
end
Chef::Log.info "Cookbook #{cookbook} version #{version} does not exist on the Chef Infra Server."
EOF
- task: chef-software.chef-azdo.execute.component@3
displayName: 'Cookbook Uploaded Check'
inputs:
component: 'chef'
arguments: 'exec knife exec $(Agent.TempDirectory)/cookbook_uploaded_check.rb -V'