0

In my use of Chocolatey to provision Jenkins build nodes, I have a need to perform certain operations before and/or after a choco upgrade (e.g., stopping the Jenkins service, or reconfiguring Git after installation).

My simplest alternative is to always do these operations regardless of whether an upgrade actually is available/was installed, but ideally I would only do them if it is. I see choco upgrade <pkg> --whatif as a way to detect a single outdated package, but short of parsing the output (e.g., looking for the string "is available"), there doesn't look like a simple way to programmatically detect the result. For example, the %ERRORLEVEL% after running this command is 0 regardless of whether an upgrade is available.

Is there a better alternative to parsing the output as suggested above, given my scenario?

Community
  • 1
  • 1
Nick Jones
  • 4,395
  • 6
  • 33
  • 44

1 Answers1

2

Have you considered using the output from the choco outdated command?

Full information on this can be found here:

https://chocolatey.org/docs/commands-outdated

The command that I think you would be after would be:

choco outdated -r

Which would give you the most relevant information, which you could quickly parse to decide if a program that you were interested in was outdated or not.

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
  • 1
    This helped me find a solution -- `choco outdated -r | find ""`, which returns 0 if it needs updating and 1 if it doesn't. – Nick Jones Jul 26 '18 at 13:12