Nick Jones
Nick Jones

Reputation: 4465

Detecting an outdated Chocolatey package programmatically

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?

Upvotes: 0

Views: 413

Answers (1)

Gary Ewan Park
Gary Ewan Park

Reputation: 18981

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.

Upvotes: 2

Related Questions