Class: Disloku::Tasks::NetSftpTask
- Defined in:
- lib/disloku/tasks/NetSftpTask.rb
Instance Attribute Summary
Attributes inherited from BaseTask
Instance Method Summary collapse
- #afterExecute ⇒ Object
- #beforeExecute ⇒ Object
- #executeTask ⇒ Object
-
#initialize(input) ⇒ NetSftpTask
constructor
A new instance of NetSftpTask.
Methods inherited from BaseTask
Constructor Details
#initialize(input) ⇒ NetSftpTask
Returns a new instance of NetSftpTask.
30 31 32 33 34 35 36 37 38 |
# File 'lib/disloku/tasks/NetSftpTask.rb', line 30 def initialize(input) super() @repository = getInputParam(input, :repository, Disloku::Repository) @options = getInputParam(input, :options, Config::Options) @directory = getInputParam(input, :directory, String) @files = getInputParam(input, :files, Array) @target = getInputParam(input, :target, Config::Target) @dirty = getInputParam(input, :dirty, Object) end |
Instance Method Details
#afterExecute ⇒ Object
108 109 |
# File 'lib/disloku/tasks/NetSftpTask.rb', line 108 def afterExecute() end |
#beforeExecute ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/disloku/tasks/NetSftpTask.rb', line 40 def beforeExecute() if (@files.count == 0) CliAdapter.puts("Nothing to deploy for target [#{@target.name}]") return false end if (!@target.branchLock.nil?) branch = @repository.getBranchName() if (branch != @target.branchLock) raise DislokuError.new("Target [#{@target.name}] is locked to branch #{@target.branchLock} but current branch is #{branch}", true) end end if (@dirty && !@target.allowDirty.nil? && !@target.allowDirty) raise DislokuError.new("Target does not allow deployments from dirty repositories", true) end CliAdapter.puts() CliAdapter.puts("Target [#{@target.name}]: #{@target.user}@#{@target.host}:#{@target.targetDir}") @files.each() do |file| puts(file) end return CliAdapter.queryYesNo("Continue with deployment?") end |
#executeTask ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/disloku/tasks/NetSftpTask.rb', line 66 def executeTask() CliAdapter.puts("Doploying target [#{@target.name}]") Log.instance.scope([:default, :logfile]) do SessionManager.instance.get(@target.connection) do |sftp| Log.instance.info("connection with [#{@target.name}] established") sftp.upload!(@directory, @target.targetDir, { :ignoreMkdirError => true }) do |event, uploader, *args| case event when :open then # args[0] : file metadata # "starting upload: #{args[0].local} -> #{args[0].remote} (#{args[0].size} bytes}" CliAdapter.print(".") Log.instance.info("#{args[0].local} -> #{args[0].remote} (#{args[0].size} bytes)") end end CliAdapter.puts() @files.each() do |file| if (file.change.changeType == :deleted) path = file.getAbsoluteDstPath() Log.instance.info("deleting file #{path}") begin sftp.remove!(path) CliAdapter.print("x") rescue if (!@options.ignoreDeleteErrors) Log.instance.fatal("unable to delete file #{path} - failing") raise else Log.instance.warn("unable to delete file #{path} (it probably doesn't exist)") end end end end end end end |