When running an ansible playbook via a shell script in Jenkins pipeline, the echo output is buffered and does not show in real time

AGomez

So below I have attached my pipeline code for Jenkins. The runansible.sh script takes in the parameters given and then proceeds to run an ansible playbook based on the paramMode value. When kicking off the shell script in a terminal I get realtime output of the ansible playbook running, but when using the Jenkins pipeline I just get the loading cogwheel during the echo stage. I do not get any echo output until the whole playbook has completed and then it spits it out all at once. I need to be able to have live output from the playbook like I do in a terminal so the progress can be monitored as the build is building. What do I need to do to get realtime output?

def paramMode = "${params.mode}"
def paramClientCode = "${params.client_code}"
def paramPrevCodeDropID = "${params.prev_code_drop_id}"
def paramCodeDropID = "${params.code_drop_id}"
def paramReleaseID = "${params.release_id}"
def paramConfigZipVer = "${params.config_zip_ver}"
def paramEmailIDs = "${params.email_ids}"

node {
    stage('one-click') {
        node ('nodeName') {
            git url: "gitURL", branch: "runParallel", credentialsId: "stash_id"
            echo sh (returnStdout: true, script: """
            ./runansible.sh ${paramMode} -h ${paramClientCode} -c ${paramCodeDropID} -r ${paramReleaseID} -v ${paramConfigZipVer} -e ${paramEmailIDs} -p ${paramPrevCodeDropID}
            """)

        }

    }

}
Wim Coenen

I think what you want is already the default behavior of sh, but you have disabled it by using returnStdout: true. This causes the output to be captured and returned, instead of printed. Then you print it with echo.

From the documentation of sh:

returnStdout (optional)

If checked, standard output from the task is returned as the step value as a String, rather than being printed to the build log. (Standard error, if any, will still be printed to the log.)

So instead of echo sh (returnStdout:true, ...) try just sh (...)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Script output is buffered into one message, despite separate echo statements?

Running Python script via ansible

Why does running "echo $-" output "himBH" on the bash shell?

Jenkins Pipeline Plugin: execute shell and parse output

Vague deprecation error when running ansible playbook

What's the difference between """ and ''' in terms of running a shell script within a Jenkins pipeline step?

Git shortlog does not show output in Jenkins shell

Capturing shell script output from Jenkins Pipeline

Jenkins Pipeline: Executing a shell script

Running nested commands in Jenkins pipeline shell

run ansible playbook on jenkins pipeline

List running java processes in a linux host via ansible playbook

KeyError: 'user' when running Ansible playbook

Location of Ansible playbook when running in Azure Cloud Shell

Not able to pass variables from Jenkins pipeline's script part to Ansible playbook

Not able to call a shell script from an ansible playbook

Ansible hangs when running playbook second time

missing host information when running ansible playbook

Jenkins pipeline shell cut command with output redirection

sudo error when running playbook in ansible

ansible - Nothing happens when executing InstallHalyard.sh script via ansible-playbook

Running Ansible playbook with ant commands in Jenkins

Running a Packer script in a Jenkins pipeline?

ansible-playbook acting differently when called in a bash script to directly on shell

jenkins pipeline deal with empty output from shell script

Running a shell script using Subprocess in Python does not produce output

How to return a message form shell script to Ansible playbook to Display as output

Execute bash script via ansible playbook

Running shell Script via Crontab

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive