jenkins_shell 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 434109caa1b231794f93f311a118f18f29eb4fbc43381e9f892221108546caae
4
- data.tar.gz: 25eed219a7b6f17a681d6b4836d4a6f7e3c6fad49a087010849ab6d41c95d16b
3
+ metadata.gz: bc19a7e7ac0de4a5dac9e02f534850b0229fdf1e064983d666f25c9b50d6c263
4
+ data.tar.gz: ef12b53b7d2a6bc2fbecffd3fc3a9d394458ebe2861c9f30d775c8be3f14f8c9
5
5
  SHA512:
6
- metadata.gz: 87c29f1f6ebd30db7a74cf0fa9e2a7bb02745c3236dbe77b2b23ce64fb990cc515e66622c60d744499e1273f5e468a88038256218e5c8f09d9718b65efc9fb51
7
- data.tar.gz: a10a1dbbfefba19c70ade3082f7193ce8cc38fc53eb1f51084cc388233c33c8fa533fb1a1400be1477c5418d721462a07f0c52c05e19eab5f6bdbc97c0daf330
6
+ metadata.gz: c1a25c31edc94c4569e53853951dc2b2c7d4bcb647ef1e20965cf727b7e7a182202e40c0b0c11b9d31ebfdb474654afdef2703b56e957b6a5515bf9f3ae2fb58
7
+ data.tar.gz: e8e141572b92e44d76c73474e44829f25518f15f7bf32571c543db519e1e7acb2ecd2649fb17479b301de6d8c1bdb22c196217dd83905f072408bd0ab54d410c
data/bin/jsh CHANGED
@@ -26,12 +26,17 @@ end
26
26
  def parse(args)
27
27
  options = Hash.new
28
28
  options["password"] = nil
29
+ options["path"] = ""
29
30
  options["port"] = "8080"
31
+ options["os"] = JenkinsShell::OS.WINDOWS
30
32
  options["ssl"] = false
31
33
  options["username"] = nil
32
34
  options["verbose"] = false
33
35
 
34
- info = "Simulate a cmd prompt using Jenkins script functionality"
36
+ info = [
37
+ "Simulate a Linux/Windows prompt using Jenkins script",
38
+ "functionality"
39
+ ].join(" ")
35
40
 
36
41
  parser = OptionParser.new do |opts|
37
42
  opts.summary_width = 26
@@ -51,17 +56,26 @@ def parse(args)
51
56
  exit JShExit::GOOD
52
57
  end
53
58
 
59
+ opts.on("-l", "--linux", "Remote OS is Linux") do
60
+ options["os"] = JenkinsShell::OS.LINUX
61
+ end
62
+
54
63
  opts.on("--nocolor", "Disable colorized output") do
55
64
  Hilighter.disable
56
65
  end
57
66
 
58
67
  opts.on(
59
68
  "--password=PASSWORD",
60
- "Use specified password (will prompt if not provided)"
69
+ "Use specified password (will prompt",
70
+ "if not provided)"
61
71
  ) do |password|
62
72
  options["password"] = password
63
73
  end
64
74
 
75
+ opts.on("--path=PATH", "Path from root of host") do |path|
76
+ options["path"] = path.gsub(/^\//, "")
77
+ end
78
+
65
79
  opts.on(
66
80
  "-p",
67
81
  "--port=PORT",
@@ -85,6 +99,14 @@ def parse(args)
85
99
  ) do
86
100
  options["verbose"] = true
87
101
  end
102
+
103
+ opts.on(
104
+ "-w",
105
+ "--windows",
106
+ "Remote OS is Windows (default)"
107
+ ) do
108
+ options["os"] = JenkinsShell::OS.WINDOWS
109
+ end
88
110
  end
89
111
 
90
112
  begin
@@ -125,20 +147,21 @@ options = parse(ARGV)
125
147
  begin
126
148
  passwd = options["password"]
127
149
  passwd = get_password if (options["username"] && passwd.nil?)
128
- jsh = JenkinsShell.new(
129
- options["host"],
130
- options["port"],
131
- options["ssl"],
132
- options["username"],
133
- passwd
134
- )
150
+ options["password"] = passwd
151
+ jsh = JenkinsShell.new(options)
135
152
 
136
153
  djinni = Djinni.new
137
154
  djinni.fallback = "cmd"
138
155
  djinni.load_wishes(
139
156
  "#{File.dirname(__FILE__)}/../lib/jenkins_shell/wish"
140
157
  )
141
- djinni.prompt({"jsh" => jsh}, "#{jsh.pwd}> ".light_white)
158
+ case options["os"]
159
+ when JenkinsShell::OS.LINUX
160
+ prompt = "#{jsh.pwd}$ ".light_white
161
+ when JenkinsShell::OS.WINDOWS
162
+ prompt = "#{jsh.pwd}> ".light_white
163
+ end
164
+ djinni.prompt({"jsh" => jsh, "os" => options["os"]}, prompt)
142
165
  rescue SystemExit
143
166
  # Quite from djinni
144
167
  # Exit gracefully
data/lib/jenkins_shell.rb CHANGED
@@ -31,8 +31,21 @@ class JenkinsShell
31
31
  end
32
32
 
33
33
  # Create Groovy script
34
- fix = dir.gsub(/\\/, "\\\\\\")
35
- gs = "println(\"cmd /c cd #{fix} && #{cmd}\".execute().text)"
34
+ gs = [
35
+ "println(\"",
36
+ "#{
37
+ case @os
38
+ when JenkinsShell::OS.LINUX
39
+ # FIXME
40
+ # "cd #{dir} && #{cmd}"
41
+ cmd
42
+ when JenkinsShell::OS.WINDOWS
43
+ "cmd /c cd #{dir.gsub(/\\/, "\\\\\\")} && #{cmd}"
44
+ end
45
+ }",
46
+ "\".execute().text",
47
+ ")"
48
+ ].join
36
49
 
37
50
  # Make POST request and return command output
38
51
  xml = post("/script", "script=#{encode(gs)}")[1]
@@ -54,7 +67,7 @@ class JenkinsShell
54
67
  http.use_ssl = @ssl
55
68
 
56
69
  # Create request
57
- req = Net::HTTP::Get.new(path)
70
+ req = Net::HTTP::Get.new("#{@path}#{path}")
58
71
  req["Cookie"] = @cookie if (@cookie)
59
72
 
60
73
  # Send request and get response
@@ -79,21 +92,40 @@ class JenkinsShell
79
92
  end
80
93
  private :get
81
94
 
82
- def initialize(
83
- host,
84
- port = 8080,
85
- ssl = false,
86
- username = nil,
87
- password = nil
88
- )
95
+ def initialize(params)
89
96
  @cookie = nil
90
97
  @crumb = nil
91
98
  @int_cwd = "."
92
- @host = host.gsub(/^https?:\/\/|(:[0-9]+)?\/.+/, "")
93
- @password = password
94
- @port = port
95
- @ssl = ssl
96
- @username = username
99
+
100
+ creds = "(([^:]+)(:(.+))?@)?"
101
+ host = "([^:/]+)"
102
+ path = "(/(.+))?"
103
+ port = "(:([0-9]+))?"
104
+ prot = "(https?)://"
105
+
106
+ params["host"].match(
107
+ /^#{prot}#{creds}#{host}#{port}#{path}/
108
+ ) do |m|
109
+ @host = m[6]
110
+ @password = m[5]
111
+ @path = m[10]
112
+ @port = m[8]
113
+ case m[1]
114
+ when "http"
115
+ @ssl = false
116
+ when "https"
117
+ @ssl = true
118
+ end
119
+ @username = m[3]
120
+ end
121
+
122
+ @os = params["os"]
123
+ @password ||= params["password"]
124
+ @path ||= params["path"]
125
+ @path = "/#{@path}" if (@path)
126
+ @port ||= params["port"] || 8080
127
+ @ssl ||= params["ssl"] || false
128
+ @username ||= params["username"]
97
129
 
98
130
  # Initialize @cwd
99
131
  @cwd = pwd
@@ -123,7 +155,7 @@ class JenkinsShell
123
155
  http.use_ssl = @ssl
124
156
 
125
157
  # Create request
126
- req = Net::HTTP::Post.new(path)
158
+ req = Net::HTTP::Post.new("#{@path}#{path}")
127
159
  req.body = body.join("&")
128
160
  req["Cookie"] = @cookie if (@cookie)
129
161
 
@@ -150,8 +182,13 @@ class JenkinsShell
150
182
  private :post
151
183
 
152
184
  def pwd(dir = @int_cwd)
153
- command("dir", dir).match(/^\s+Directory of (.+)/) do |m|
154
- return m[1]
185
+ case @os
186
+ when JenkinsShell::OS.LINUX
187
+ return command("pwd", dir)
188
+ when JenkinsShell::OS.WINDOWS
189
+ command("dir", dir).match(/^\s+Directory of (.+)/) do |m|
190
+ return m[1]
191
+ end
155
192
  end
156
193
  return ""
157
194
  end
@@ -171,3 +208,4 @@ class JenkinsShell
171
208
  end
172
209
 
173
210
  require "jenkins_shell/error"
211
+ require "jenkins_shell/os"
@@ -0,0 +1,9 @@
1
+ class JenkinsShell::OS
2
+ def self.LINUX
3
+ return 1
4
+ end
5
+
6
+ def self.WINDOWS
7
+ return 2
8
+ end
9
+ end
@@ -11,6 +11,12 @@ class CDWish < Djinni::Wish
11
11
  end
12
12
 
13
13
  def execute(args, djinni_env = Hash.new)
14
+ case djinni_env["os"]
15
+ when JenkinsShell::OS.LINUX
16
+ puts "Currently unsupported for Linux"
17
+ return
18
+ end
19
+
14
20
  usage if (args.empty?)
15
21
 
16
22
  jsh = djinni_env["jsh"]
@@ -19,7 +25,12 @@ class CDWish < Djinni::Wish
19
25
  return
20
26
  end
21
27
 
22
- djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
28
+ case djinni_env["os"]
29
+ when JenkinsShell::OS.LINUX
30
+ djinni_env["djinni_prompt"] = "#{jsh.cwd}$ ".light_white
31
+ when JenkinsShell::OS.WINDOWS
32
+ djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
33
+ end
23
34
  end
24
35
 
25
36
  def usage
@@ -14,7 +14,13 @@ class CmdWish < Djinni::Wish
14
14
 
15
15
  jsh = djinni_env["jsh"]
16
16
  puts jsh.command(args)
17
- djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
17
+
18
+ case djinni_env["os"]
19
+ when JenkinsShell::OS.LINUX
20
+ djinni_env["djinni_prompt"] = "#{jsh.cwd}$ ".light_white
21
+ when JenkinsShell::OS.WINDOWS
22
+ djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
23
+ end
18
24
  end
19
25
 
20
26
  def usage
@@ -11,8 +11,15 @@ class LSWish < Djinni::Wish
11
11
 
12
12
  def execute(args, djinni_env = Hash.new)
13
13
  jsh = djinni_env["jsh"]
14
- puts jsh.command("dir #{args}")
15
- djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
14
+
15
+ case djinni_env["os"]
16
+ when JenkinsShell::OS.LINUX
17
+ puts jsh.command("ls #{args}")
18
+ djinni_env["djinni_prompt"] = "#{jsh.cwd}$ ".light_white
19
+ when JenkinsShell::OS.WINDOWS
20
+ puts jsh.command("dir #{args}")
21
+ djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
22
+ end
16
23
  end
17
24
 
18
25
  def usage
@@ -14,7 +14,13 @@ class PwdWish < Djinni::Wish
14
14
 
15
15
  jsh = djinni_env["jsh"]
16
16
  puts jsh.pwd if (args.empty?)
17
- djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
17
+
18
+ case djinni_env["os"]
19
+ when JenkinsShell::OS.LINUX
20
+ djinni_env["djinni_prompt"] = "#{jsh.cwd}$ ".light_white
21
+ when JenkinsShell::OS.WINDOWS
22
+ djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
23
+ end
18
24
  end
19
25
 
20
26
  def usage
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins_shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Whittaker
@@ -71,7 +71,7 @@ dependencies:
71
71
  - !ruby/object:Gem::Version
72
72
  version: 1.2.3
73
73
  description: This gem will use the scripting functionality of Jenkins to simulate
74
- a Windows cmd prompt.
74
+ a Linux shell or Windows cmd prompt.
75
75
  email: mjwhitta@gmail.com
76
76
  executables:
77
77
  - jsh
@@ -84,6 +84,7 @@ files:
84
84
  - lib/jenkins_shell/error/connection_refused.rb
85
85
  - lib/jenkins_shell/error/invalid_html_received.rb
86
86
  - lib/jenkins_shell/error/login_failure.rb
87
+ - lib/jenkins_shell/os.rb
87
88
  - lib/jenkins_shell/wish/cd_wish.rb
88
89
  - lib/jenkins_shell/wish/cmd_wish.rb
89
90
  - lib/jenkins_shell/wish/ls_wish.rb
@@ -111,5 +112,5 @@ rubyforge_project:
111
112
  rubygems_version: 2.7.7
112
113
  signing_key:
113
114
  specification_version: 4
114
- summary: Simulate a cmd prompt using Jenkins.
115
+ summary: Simulate a Linux/Windows prompt using Jenkins.
115
116
  test_files: []