cli icon indicating copy to clipboard operation
cli copied to clipboard

octopus task wait cli command does not return if shelled out to from ruby

Open ohTHATaaronbrown opened this issue 8 months ago • 0 comments

The bug

Shelling out to octopus task wait in ruby with Open3.popen3 never returns. Even when specifying --no-prompt and/or --output-format json. Even when the task has completed on the server. The calling ruby code will just flat-out never continue past the point where the call to octopus task wait was made.

Note that the same code block below works fine with a call to octopus runbook run.

The lack of ability to successfully wait on the outcome of a runbook invocation's task makes the octopus cli useless in my process. I had to fall back to the deprecated octo cli that was discontinued in 2022 to get a working wait-on-outcome workflow.

What I'm after is the equivalent behavior to this call to the deprecated cli:

octo run-runbook --runbook="my_deployment_runbook" --progress --logLevel="information" --waitForRun --runCheckSleepCycle="00:00:05" --runTimeout="30" --project="my_ops_project" --environment="my_test_environment"

Command to reproduce

require 'open3'
result = {messages: [], errors: [] }
command_name = 'task wait'

command_line = '/usr/local/bin/octopus task wait "ServerTasks-358388" --space "Spaces-1" --timeout 60 --no-prompt --output-format json'

Open3.popen3(command_line) do |stdin, stdout, stderr, wait_thr|
  stdout.each do |line|
    line.chomp!
    if line.length.positive?
      trimmed_line = line.strip.squeeze("\t", ' ')
      result[:messages] << trimmed_line
    end
  end
  
  stderr.each do |line|
    line.chomp!
    if line.length.positive?
      trimmed_line = line.strip.squeeze("\t", ' ')
      result[:errors] << trimmed_line
      logger.error "#{trimmed_line}"
    end
  end
  
  exit_status = wait_thr.value
  exit_message = ''
  if exit_status.success?
    exit_message = "#{command_name} result: succeeded"
    result[:messages] << exit_message
    result[:overall_result] = :succeeded
    logger.info exit_message
  else
    exit_message = "#{command_name} returned a failure code: #{exit_status.exitstatus}."
    result[:messages] << exit_message
    result[:overall_result] = :failed_unexpected_exit_code
    logger.warn exit_message
  end
end

Outcome

### crickets...

Versions

cli: 1.8.0

Octopus Server: 2025.1.10012

cli running on: macOS Sequoia 15.5 (24F74) on m4 max macbook pro, ruby 3.4.1

Links

Probably related to #290 and #379

ohTHATaaronbrown avatar May 29 '25 22:05 ohTHATaaronbrown