Chris McKenzie
Chris McKenzie

Reputation: 3841

Pushing Gem to Hosted Credentialed Feed Is Failing

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

My environment is:

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.

Upvotes: 1

Views: 1117

Answers (2)

Chris McKenzie
Chris McKenzie

Reputation: 3841

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

Upvotes: 0

Chris McKenzie
Chris McKenzie

Reputation: 3841

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.

Upvotes: 2

Related Questions