Chef - 使用remote_file资源从Nexus下载Artifact

时间:2016-04-19 16:28:14

标签: chef nexus recipe

我正在使用Chef将war文件从nexus下载到一个文件夹中。食谱如下

    Label label = toolkit.createLabel(container, "Resource Type":);
    label.setLayoutData(new TableWrapData(TableWrapData.LEFT,TableWrapData.MIDDLE));
label.setBackground(DiagramSettings.NODE_BACKGROUND_COLOR);
    resourceComboMenu = new Combo(container, SWT.READ_ONLY);
resourceComboMenu.setBackground(DiagramSettings.NODE_BACKGROUND_COLOR); 
    resourceComboMenu.setLayoutData(new TableWrapData(TableWrapData.LEFT,TableWrapData.MIDDLE));

但是,如果我运行此配方,我将收到未经授权的访问错误

是否有必要为nexus登录提供用户名和密码?

我应该编写一个批处理脚本来从nexus而不是配方下载吗?

3 个答案:

答案 0 :(得分:2)

首先,我会验证您的Nexus服务器是否需要身份验证才能下载任何文件。我是通过在隐身模式下打开您的浏览器来执行此操作,然后转到source资源的remote_file属性的网址。我希望它能为您提供一个“未经授权的访问错误”的登录页面。这将证实您的问题是必须为Nexus登录提供用户名和密码。

为此,您可以使用header资源的remote_file属性将必要的凭据传递到Nexus服务器。

有关此内容的详细信息,请点击此处。 https://docs.chef.io/resource_remote_file.html#properties

我并不特别了解Nexus的登录方法,但它可能看起来像文档页面中的这个示例。 headers( "Authorization"=>"Basic #{ Base64.encode64("#{username}:#{password}").gsub("\n", "") }" )

答案 1 :(得分:0)

这就是我的做法(基于 coderanger 回答)。

nodejs_url = node['ci_cd']['ubu_nodejs_url']
...

remote_file nodejs_path do                                                                                          
  source   nodejs_url.gsub(/(https?:\/{2})/, '%s%s:%s@' % ['\1', artifactory_user, artifactory_pass])        
  checksum nodejs_url_checksum                                                                               
  owner    'root'                                                                                            
  group    'root'                                                                                            
  mode     '0644'                                                                                            
  notifies :install, 'dpkg_package[nodejs]', :immediately                                                    
  not_if   { ::File.exists?(nodejs_path) }                                                                            
end

dpkg_package 'nodejs' do                                                                                            
  source nodejs_path                                                                                               
  action :nothing                                                                                                  
end

在这个例子中,我创建了remote_filedpkg_package之间的依赖关系,只是为了在一个地方管理守卫(not_if)。

答案 2 :(得分:0)

要在Windows Machine上下载Nexus工件,请执行以下操作:

   remote_file  'D:/local/Chef/file.zip' do    
   source 'https://Nexus_URL_Address/file.zip'
   username = 'xxxx'
   password = 'xxxxxxx'
   headers( "Authorization"=>"Basic #{ Base64.encode64("#{username}:#{password}").gsub("\n", "") }" )
   end
相关问题