我的script.sh
文件夹中有简单的bash脚本/home/ubuntu/jenkins/workspace
。这个bash脚本运行 -
cd /home/ubuntu/tools; /home/ubuntu/.rbenv/shims/ruby script.rb
在这个ruby脚本中,我有几个API键的环境变量,它看起来就是脚本遇到问题的地方。以下是我在jenkins收到post post build任务时收到的错误消息 -
Performing Post build task...
Match found for : : True
Logical operation result is TRUE
Running script : /home/ubuntu/jenkins/workspace/script.sh
[Ansible-Deploy] $ /bin/sh -xe /tmp/jenkins3728886043127394122.sh
+ /home/ubuntu/jenkins/workspace/script.sh
/home/ubuntu/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/graphql-1.7.13/lib/graphql/schema/loader.rb:16:in `fetch': key not found: "data" (KeyError)
from /home/ubuntu/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/graphql-1.7.13/lib/graphql/schema/loader.rb:16:in `load'
from /home/ubuntu/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/graphql-client-0.12.2/lib/graphql/client.rb:52:in `load_schema'
from /home/ubuntu/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/graphql-client-0.12.2/lib/graphql/client.rb:60:in `load_schema'
from /home/ubuntu/tools/script.rb:274:in `<module:Github>'
from /home/ubuntu/tools/script.rb:264:in `<main>'
POST BUILD TASK : FAILURE
END OF POST BUILD TASK : 0
在第264行 -
附近的script.rb文件中GITHUB_ACCESS_TOKEN = ENV['GITHUB_ACCESS_TOKEN']
...
module Github
HttpAdapter ||= GraphQL::Client::HTTP.new(URL) do
def headers(context)
{
"Authorization" => "Bearer #{GITHUB_ACCESS_TOKEN}",
"User-Agent" => 'Ruby'
}
end
end
Schema ||= GraphQL::Client.load_schema(HttpAdapter)
Client ||= GraphQL::Client.new(schema: Schema, execute: HttpAdapter)
end
重要的是要注意,在ssh'd中运行bash脚本或ruby脚本工作正常时,它只会在从jenkins post build任务运行时失败。