Help to resolve JIRA::HTTPError: Not Found error while executing a ruby file from policies file.
Behaviour
I am currently making use of .triage-policies file for some automation in which I have a function that uses the [jira-ruby]() gem to connect to the ,local JIRA server setup.
The curent URL is of the format https://jira.xxx.xx
For the policies file I am currently using the gitlab-triage project, which has an option to mention a function which is written inside the custom .rb files and those functions are executed.
Approach
The following is the code snippet that is used to connect to the JIRA using the gem
# frozen_string_literal: true
require 'jira-ruby'
require 'json'
module Test
module Jira
# Connection to JIRA API.
class Connection
API_TOKEN = ENV.fetch('JIRA_USER_TOKEN', nil)
attr_reader :client
def initialize
@params = {
site: 'https://jira.xxx.xx:443',
context_path: '',
username: ENV.fetch('JIRA_USERNAME', nil),
password: ENV.fetch('JIRA_USER_TOKEN', nil),
auth_type: :basic,
use_ssl: true,
ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
}
@client = JIRA::Client.new(@params)
end
def find_project()
client.Project.find((ENV.fetch('JIRA_PROJECT_ID', nil)))
rescue JIRA::HTTPError => e
puts 'Error while finding project'
puts e.response.code
puts e.response.message
end
end
end
end
The code written above works fine if I write it inside a file called test.rb and execute it with the commands ruby test.rb OR bundle exec ruby test.rb. The output that I get in this approach is as below..
$ ruby test.rb
For a better Pry experience on Windows, please use ansicon:
https://github.com/adoxa/ansicon
If you use an alternative to ansicon and dont want to see this warning again,
you can add "Pry.config.windows_console_warning = false" to your pryrc.
- When I try to execute the same snippet of code but using the policies file... it gives me the following error.
`
[4] pry(#<Test::Jira::Connection>)> client.Project.find('<<id>>') JIRA::HTTPError: Not Found from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/jira-ruby-2.2.0/lib/jira/request_client.rb:13:in request'`
`
- I am currently uncertain of why the issue is present only when I run the code using a `policies` file and not the standalone `.rb` file.
- I have all the `env`and `proxies` setup, and I can get the data using the API call using Postman.
![image](https://user-images.githubusercontent.com/11441603/213566313-739c967b-9119-401e-9c8b-86030982db61.png)
- STRUCTURE OF THE POLICIES FILE
![image](https://user-images.githubusercontent.com/11441603/213730085-cdffb04d-77c8-4485-8e74-74e0d4b54443.png)
Any help would be great!
Thank you.
Help to resolve JIRA::HTTPError: Not Found error while executing a ruby file from policies file.
Behaviour
.triage-policies
file for some automation in which I have a function that uses the [jira-ruby
]() gem to connect to the ,local JIRA server setup.https://jira.xxx.xx
gitlab-triage
project, which has an option to mention a function which is written inside the custom.rb
files and those functions are executed.Approach
The code written above works fine if I write it inside a file called
test.rb
and execute it with the commandsruby test.rb
ORbundle exec ruby test.rb
. The output that I get in this approach is as below..$ ruby test.rb For a better Pry experience on Windows, please use ansicon: https://github.com/adoxa/ansicon If you use an alternative to ansicon and dont want to see this warning again, you can add "Pry.config.windows_console_warning = false" to your pryrc.
C:/Users/User_Name/Documents/test.rb:343 :
=> 343: binding.pry
[1] pry(main)> client.Project.find('<>')
=> #<JIRA::Resource::Project:0x000002bc4356f660
@attrs=
{"key"=>"<>",
"expand"=>"description,lead,url,projectKeys",
"self"=>"https://jira.xxx.xxx.xx/rest/api/2/project/<>",
"id"=>"<>",
"description"=>"",
"lead"=>