简体   繁体   English

无法使用Puppet检出SVN存储库

[英]Unable to checkout SVN repo using Puppet

I am trying to checkout code from SVN repo for which I am accepting the URL as argument. 我正在尝试从SVN存储库中检出我接受URL作为参数的代码。 I have quoted the URL as shown below because it contains spaces. 我引用了如下所示的URL,因为它包含空格。 I also checked the parameter by redirecting the $svn_url in file (shown below). 我还通过重定向文件中的$svn_url (如下所示)来检查参数。 If I pick the URL from the file and pass it as is on the command line to the given script, it works fine but somehow when invoked from Puppet, it's not working. 如果我从文件中选择URL并将其命令行传递给给定脚本,它可以正常工作,但是以某种方式从Puppet调用时,它将无法正常工作。

Puppet manifests: 木偶表现:

repo_checkout.pp : 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 : params.pp

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

site.pp : 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 : 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 code: 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'

Puppet output on agent node: 代理节点上的人偶输出:

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

Content of c:\\svn_url : c:\\svn_url

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

UPDATE: Sorry for the confusion but i was trying out several permutations and combinations and in doing that, i forgot to mention that when the $svn_url contains backslash (\\) , it does NOT work on the command line too if i copy the SVN URL from the text file where i am redirecting the echo output. 更新:很抱歉的混乱,但我尝试了几种排列组合,并在这样做,我忘了提,当$svn_url包含反斜线(\\)它并没有在命令行上,如果我复制SVN URL工作太从我重定向echo输出的文本文件中。

Based on @Ansgar's suggestion, i changed '$svn_url' to "$svn_url" in powershell code but the output in text file then contained ' quote twice around the URL. 根据@安斯加尔的建议下,我改变了'$svn_url'"$svn_url"在PowerShell中的代码,但在随后的文本文件输出包含'报价的两倍左右的URL。 So i changed the argument parameter from "\\'\\"$svn_url\\"\\'" to "\\"$svn_url\\"" . 所以我将argument参数从"\\'\\"$svn_url\\"\\'"更改为"\\"$svn_url\\"" Now the output file had only single quote present around the URL. 现在,输出文件的URL周围只有单引号。 I copied only the URL (along with single quotes around it) from the output file and tried passing it to the powershell script. 我仅从输出文件中复制了URL(并带有单引号),然后尝试将其传递给powershell脚本。 I now get the following error: 我现在收到以下错误:

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

Another thing to note is that if i change the back slashes in URL to forward slashes, it works fine on the command line. 另外要注意的是,如果我改变反斜杠在URL正斜杠,它工作正常 ,在命令行上。 Invoking from Puppet still doesn't work. 从Puppet调用仍然无效。

Posting the final configuration that worked out for me based on @AnsgarWiechers' suggestion. 根据@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
}

Thanks a lot @AnsgarWiechers! 非常感谢@AnsgarWiechers! :) :)

Note: 注意:

  • In site.pp : Used forwardslashes (/) when specifying svn_url site.pp中 :指定svn_url时使用正斜杠 (/)
  • In repo_checkout.ps1 : Changed '$svn_url' to "$svn_url" repo_checkout.ps1中 :将'$svn_url'更改为"$svn_url"
  • In repo_checkout.pp : Changed double-nested ( ' and " ) quoting in argument to single ( " ) nested ie, from "\\'\\"$svn_url\\"\\'" to "\\"$svn_url\\"" repo_checkout.pp:改变双嵌套( '" )引用在argument到单个( " )嵌套即,从"\\'\\"$svn_url\\"\\'""\\"$svn_url\\""

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

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