Jenkins Pipeline Plugin: execute shell and parse output

亡梦爱人 提交于 2019-12-30 17:04:39

问题


I am using the Jenkins Pipeline plugin to execute an iOS Checkout-Build-Test-Deploy pipeline.

One step involves checking whether an iDevice is actually connected (otherwise the rest of the steps will not be executed).

I want to execute a shell command idevice_id -l (from libimobiledevice) which will print out the device ID of the connected device, or fail if nothing connected.

So the steps as I envision them, would be:

  • Execute command sh "/usr/local/bin/idevice_id -l"
  • parse the output somehow
  • fail if this command does not return anything.

I have read most of the official docs, but drew a blank. How do I parse the output of the sh step? If I am approaching this in the wrong way, any other suggestions are welcome.


回答1:


As mentionned in this answer, as of version 2.4 of Pipeline: Nodes and Processes you can use:

def out = sh script: '/usr/local/bin/idevice_id -l', returnStdout: true



回答2:


The official method is to redirect the output into a file and read the file

If the output file is empty, you can fail the job with the pipeline script command error "no device connected"

Example on github



来源:https://stackoverflow.com/questions/36304131/jenkins-pipeline-plugin-execute-shell-and-parse-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!