1

I'm trying to push a gem to hosted Artifactory and am encountering problems every step of the way.

My environment is:

  • Operating System: Windows 7 x64 Professional
  • Ruby: ruby 1.9.3p545

I had to do a trick with cacert.pem to add the artifactory url to my list of sources, but that part is working now. The next step in Artifactory documentation is to get an api key and pipe it to ~/.gem/credentials.

When I do that the api key downloads successfully, but gem completely breaks.

gem
C:/ruby193/lib/ruby/1.9.1/psych.rb:203:in `parse': (<unknown>): control characters are not allowed at line 1 column 1 (Psych::SyntaxError)
        from C:/ruby193/lib/ruby/1.9.1/psych.rb:203:in `parse_stream'
        from C:/ruby193/lib/ruby/1.9.1/psych.rb:151:in `parse'
        from C:/ruby193/lib/ruby/1.9.1/psych.rb:127:in `load'
        from C:/ruby193/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:253:in `load_file'
        from C:/ruby193/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:223:in `load_api_keys'
        from C:/ruby193/lib/ruby/site_ruby/1.9.1/rubygems/config_file.rb:208:in `initialize'
        from C:/ruby193/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:78:in `new'
        from C:/ruby193/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:78:in `do_configuration'
        from C:/ruby193/lib/ruby/site_ruby/1.9.1/rubygems/gem_runner.rb:51:in `run'

I can't even use gem as long as the credentials file is there, so I have to remove it.

If I try to push without the credentials file and using the --host option, gem seems to ignore the --host options.

gem push .\my_gem-0.0.1.0.beta.gem --host $artifactory.source
Enter your RubyGems.org credentials.
Don't have an account yet? Create one at http://rubygems.org/sign_up
   Email:
Password:
Pushing gem to https://rubygems.org...
HTTP Basic: Access denied.

This is a proprietary gem, so publishing to rubygems.org is NOT an option. There definitely seems to be a problem with my environment, but I've been unable to figure out what it is--and none of the other documentation of SO questions seem to be on point.

I know that I'm going to need to get gem to read the credentials file to push successfully, but it seems like a more basic issue that gem is ignoring the --host parameter.

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
Chris McKenzie
  • 3,681
  • 3
  • 27
  • 36
  • Did you verify that the content of the `%USERPROFILE%/.gem/credentials` file is valid? Did you try to use the `RUBYGEMS_HOST` environment variable instead of --host? – Dror Bereznitsky Aug 07 '14 at 06:20
  • It looks like your api key contains illegal characters. That might be a bug. Can you change the password in Artifactory easily (I mean - doesn't it come from LDAP or something)? If you can, please share your api key in the question (and change the password, of course, afterwards). That will help to answer. – JBaruch Aug 07 '14 at 06:22
  • Setting the RUBYGEMS_HOST environment variable seems to help, though I'm confused as to why this is necessary and why the --host option doesn't work. I'm also confused about why gems is still prompting me for rubygems.org credentials when I'm not pushing to rubygems.org. I still can't push the gem due to the credentials issue. Output in the next comment: – Chris McKenzie Aug 07 '14 at 15:31
  • $env:RUBYGEMS_HOST = $artifactory.url gem push .\my_gem-0.0.1.0.beta.gem Enter your RubyGems.org credentials. Don't have an account yet? Create one at http://rubygems.org/sign_up Email: Password: Pushing gem to http://myartifactoryurl.com/... { "errors" : [ { "status" : 401, "message" : "Bad credentials" } ] } – Chris McKenzie Aug 07 '14 at 15:31
  • ---\n :rubygems_api_key: Basic Z3Vlc3RhZG1pbjpwYXNzd29yZDE= I'll be changing the password obviously. :) – Chris McKenzie Aug 07 '14 at 15:33

2 Answers2

2

It took a lot of effort, but I think I've resolved my issues. It was a problem in 2 parts.

Solution Part 1

With respect to the issue of gem ignoring the --host option, this is resolved by updating gem.

Apparently the version of gem that ships with ruby 1.9.3v545 on Windows is broken. After updating gem it acted like it was trying to upload to the correct url.

Solution Part 2

The second issue involves a corrupted credentials file. What's happening here is that when piping the output from the curl command into the credentials file, the credentials file is being encoded with Unicode. To resolve this I used a slightly different curl command (in powershell)

curl $url | Out-File ~/.gem/credentials -Encoding "ASCII"

Now I'm able to upload the gem successfully.

Community
  • 1
  • 1
Chris McKenzie
  • 3,681
  • 3
  • 27
  • 36
0

If the SSL_CERT_FILE environment variable trick doesn't work, you can also try editing your .gemrc file as follows:

:ssl_ca_cert: C:\\path\\to\\cacert.pem
Chris McKenzie
  • 3,681
  • 3
  • 27
  • 36