2017-11-09 11 views
0

私のリポジトリはAWS CodeCommitにあります。私は、CLI AWSを設定するには、コマンドを実行していますレポジトリがAWS CodeCommitの場合、Windows上のChefレシピからGITコマンドを実行するには?

aws configure --profile test 

私は私のIAMユーザーに「AWSCodeCommitPowerUser」ポリシーが割り当てられています。 私はAWSプロファイルを使用するように私のGITの資格情報マネージャを指摘している:

git config --global credential.helper '!aws --profile test codecommit credential-helper [email protected]' 
git config --global credential.UseHttpPath true 

私は.awsディレクトリと.gitconfigファイルが正しくC内部の私のユーザーのために作成されていることを確認しました:\ユーザー[my_user] \

\私は、私のPowerShellコンソールから、必要なgit制御ディレクトリのgit pullコマンドを実行できることを確認しました。

しかし、シェフのレシピから同じコマンドを実行すると、gitディレクトリが更新されません。私はgitタイムアウトエラーを受け取り、タスクマネージャーでGit Credential Managerタスクが実行されていることに気付きました。その後、私のレシピは失敗します。私のシェフクライアントはバージョン:12.14.89

どのように動作させるには?

+0

シェフのレシピを実行しているユーザーは?別のユーザーであるか、別のユーザーとして開始されたサービスを介して実行している場合は、そのユーザーのawsとgitの両方を設定する必要があります。 – arco444

+0

windows_taskリソース経由でシェフクライアントを実行しています。ドメインユーザーのためのものを設定しました。 – Chiranjib

答えて

1

まず、失敗した努力の要約:

powershell_script 'git-sync' do 
    cwd "#{ENV['HOME']}']}" 
    code <<-EOH 
     git pull 
    EOH 
end 
リソースが

ruby_block 'git-sync' do 
    block do 
     script <<-EOH 
      git pull 
     EOH 
    end 
    result = powershell_out(script) 
    if (!result.stdout.to_s.empty?) 
     Chef::Log.info("GIT command output::\n#{result.stdout.to_s}") 
    end 
end 

同じ問題を-noprofileタグでPowerShellを実行し、ユーザーの設定がロードされていないので、

が動作しない、doesnの仕事はありません。 1の理由は、いくつかのnilのディレクトリに文句不合理なエラーのuser属性を指定する必要がありますし、失敗したので yser

git "#{node.run_state['git_directory']}" do 
    repository "#{node.run_state['git_repo']}" 
    revision "#{node.run_state['git_branch']}" 
    action :sync 
    user "#{ENV['USER']}" 
end 

上記1は動作しません。

レシピgit_sync.rb

検査時には、私は、今、リソースだけおそらく基礎となるルビーファイルがEtc.getpwnam(..)を使用してLinuxで動作するだろうとソリューションを

を実現しました

ruby_block 'git-sync' do 
    block do 
    psFile = "#{Chef::Config[:file_cache_path]}/cookbooks/#{cookbook_name}/files/git_align.ps1" 
    node.run_state['git_directories'].each { |location| 
     scriptOutput = `powershell.exe -NoLogo -NonInteractive -File #{psFile} #{location} #{node.run_state['git_branch']}` 
     Chef::Log.info("Git Sync Output::\n#{scriptOutput}") 
    } 
    end 
end 

PowerShellスクリプトgit_align.ps1

Param(
    [string]$location, 
    [string]$branch_name 
) 
Try{ 
    $output = "" 
    $loc = Resolve-Path -path $location 
    if ($loc -eq $null) {throw "$location not found"} 
    Set-Location $loc 
    $output+= "At location $loc`n" 

    $curr_branch = git rev-parse --abbrev-ref HEAD 
    if ($curr_branch -ne $branch_name){ 
    $output+= git checkout $branch_name 
    $output+= "`n" 
    } 
    if ($? -eq $false) {throw "GIT checkout failed"} 

    $output+= git reset --hard origin/$branch_name 
    $output+= "`n" 
    if ($? -eq $false) {throw "GIT reset failed"} 

    $output+= git pull 
    $output+= "`n" 
    if ($? -eq $false) {throw "GIT pull failed"} 

    Write-Output $output 
} 
Catch{ 
    $exc = $_.Exception | format-list -force 
    Write-Output $exc 
    Throw $exc 
} 

希望すると助かります!シェフは海のように見えることもあり、誰も一人で泳げる必要はありません!

関連する問題