繁体   English   中英

无法使用Puppet检出SVN存储库

[英]Unable to checkout SVN repo using Puppet

我正在尝试从SVN存储库中检出我接受URL作为参数的代码。 我引用了如下所示的URL,因为它包含空格。 我还通过重定向文件中的$svn_url (如下所示)来检查参数。 如果我从文件中选择URL并将其命令行传递给给定脚本,它可以正常工作,但是以某种方式从Puppet调用时,它将无法正常工作。

木偶表现:

repo_checkout.pp

define infra::svn::repo_checkout ($svn_url_params) {
    $svn_url = $svn_url_params[svn_url]

    include infra::params
    $repo_checkout_ps = $infra::params::repo_checkout_ps

    file { $repo_checkout_ps:
        ensure => file,
        source => 'puppet:///modules/infra/repo_checkout.ps1',
    }

    util::executeps { 'Checking out repo':
        pspath   => $repo_checkout_ps,
        argument => "\'\"$svn_url\"\'",
    }
}

params.pp

$repo_checkout_ps = 'c:/scripts/infra/repo_checkout.ps1',

site.pp

$svn_url_ad = {
    svn_url => 'https:\\\\some_repo.abc.com\svn\dir  with  space\util',
}

infra::svn::repo_checkout { "Checking out code in C:\build":
    svn_url_params => $svn_url_ad
}

executeps.pp

define util::executeps ($pspath, $argument) {
    $powershell = 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NoLogo -NonInteractive'
    exec { "Executing PS file \"$pspath\" with argument \"$argument\"":
        command => "$powershell -file $pspath $argument",
        timeout => 900,
    }
}

PowerShell代码:

$svn_url = $args[0]
Set-Location C:\build
echo "svn co --username user --password xxx --non-interactive '$svn_url'" | Out-File c:\svn_url
svn co --username user --password xxx --non-interactive '$svn_url'

代理节点上的人偶输出:

Util::Executeps[Checking out repo]/Exec[Executing PS file "c:/scripts/infra/repo_checkout.ps1" with argument "'"https:\\some_repo.abc.com\svn\dir  with  space\util"'"]/returns: executed successfully
Notice: Applied catalog in 1.83 seconds

c:\\svn_url

'https:\\\\some_repo.abc.com\svn\dir  with  space\util'

更新:很抱歉的混乱,但我尝试了几种排列组合,并在这样做,我忘了提,当$svn_url包含反斜线(\\)它并没有在命令行上,如果我复制SVN URL工作太从我重定向echo输出的文本文件中。

根据@安斯加尔的建议下,我改变了'$svn_url'"$svn_url"在PowerShell中的代码,但在随后的文本文件输出包含'报价的两倍左右的URL。 所以我将argument参数从"\\'\\"$svn_url\\"\\'"更改为"\\"$svn_url\\"" 现在,输出文件的URL周围只有单引号。 我仅从输出文件中复制了URL(并带有单引号),然后尝试将其传递给powershell脚本。 我现在收到以下错误:

svn: E020024: Error resolving case of 'https:\\some_repo.abc.com\svn\dir  with  space\util'

另外要注意的是,如果我改变反斜杠在URL正斜杠,它工作正常 ,在命令行上。 从Puppet调用仍然无效。

根据@AnsgarWiechers的建议,发布对我有用的最终配置。

[tom@pe-server] cat repo_checkout.pp
define infra::svn::repo_checkout ($svn_url_params) {
    $svn_url = $svn_url_params[svn_url]
    ...
    ...
    util::executeps { 'Checking out repo':
        pspath   => $repo_checkout_ps,
        argument => "\"$svn_url\"",
    }
}

[tom@pe-server] cat repo_checkout.ps1
$svn_url = $args[0]
Set-Location C:\build
svn co --username user --password xxx --non-interactive "$svn_url"

[tom@pe-server] cat params.pp
$repo_checkout_ps = 'c:/scripts/infra/repo_checkout.ps1',

[tom@pe-server] cat site.pp
$svn_url_ad = {
    svn_url => 'https://some_repo.abc.com/svn/dir  with  space/util',
}

infra::svn::repo_checkout { "Checking out code in C:\build":
    svn_url_params => $svn_url_ad
}

非常感谢@AnsgarWiechers! :)

注意:

  • site.pp中 :指定svn_url时使用正斜杠 (/)
  • repo_checkout.ps1中 :将'$svn_url'更改为"$svn_url"
  • repo_checkout.pp:改变双嵌套( '" )引用在argument到单个( " )嵌套即,从"\\'\\"$svn_url\\"\\'""\\"$svn_url\\""

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM