Pass variables extracted from shell in Jenkinsfile


devops84uk

I'm trying to pass a variable extracted in a stage in a Jenkinsfile between stages. E.g:

   stage('Dummy Stage') {
    sh '''#!/bin/bash -l
        export abc=`output of some command`
        .....
        .....
       '''

Now, how do I pass the variable abc to subsequent stages? I tried setting the variable by adding a def section at the top of the file, but it doesn't seem to work. In the absence of a neater way, I have to retype the command

Michael

Here's what I'm doing to get the number of commits on master as a global environment variable:

pipeline {

    agent any

    environment {
        COMMITS_ON_MASTER = sh(script: "git rev-list HEAD --count", returnStdout: true).trim()
    }

    stages {

        stage("Print commits") {
            steps {
                echo "There are ${env.COMMITS_ON_MASTER} commits on master"
            }
        }
    }
}

Related


Pass variables extracted from shell in Jenkinsfile

devops84uk I'm trying to pass a variable extracted in a stage in a Jenkinsfile between stages. E.g: stage('Dummy Stage') { sh '''#!/bin/bash -l export abc=`output of some command` ..... ..... ''' Now, how do I pass the va

Pass variables extracted from shell in Jenkinsfile

devops84uk I'm trying to pass a variable extracted in a stage in a Jenkinsfile between stages. E.g: stage('Dummy Stage') { sh '''#!/bin/bash -l export abc=`output of some command` ..... ..... ''' Now, how do I pass the va

Pass variables extracted from shell in Jenkinsfile

devops84uk I'm trying to pass a variable extracted in a stage in a Jenkinsfile between stages. E.g: stage('Dummy Stage') { sh '''#!/bin/bash -l export abc=`output of some command` ..... ..... ''' Now, how do I pass the va

Pass variables extracted from shell in Jenkinsfile

devops84uk I'm trying to pass a variable extracted in a stage in a Jenkinsfile between stages. E.g: stage('Dummy Stage') { sh '''#!/bin/bash -l export abc=`output of some command` ..... ..... ''' Now, how do I pass the va

Pass variables extracted from shell in Jenkinsfile

devops84uk I'm trying to pass a variable extracted in a stage in a Jenkinsfile between stages. E.g: stage('Dummy Stage') { sh '''#!/bin/bash -l export abc=`output of some command` ..... ..... ''' Now, how do I pass the va

Pass variables extracted from shell in Jenkinsfile

devops84uk I'm trying to pass a variable extracted in a stage in a Jenkinsfile between stages. E.g: stage('Dummy Stage') { sh '''#!/bin/bash -l export abc=`output of some command` ..... ..... ''' Now, how do I pass the va

How to pass variables from Jenkinsfile to shell command

Joe: I would like to use a variable inside a Jenkinsfilescript and then pass its value to shell script execution (either as an environment variable or command line argument). But the following Jenkinsfile: for (i in [ 'a', 'b', 'c' ]) { echo i sh 'echo

How to pass variables from Jenkinsfile to shell command

Joe: I would like to use a variable inside a Jenkinsfilescript and then pass its value to shell script execution (either as an environment variable or command line argument). But the following Jenkinsfile: for (i in [ 'a', 'b', 'c' ]) { echo i sh 'echo

Pass variables from shell script configuration file

Data mastery: I am going to write a shell script to install various services dynamically. I don't know much about shell scripting or Unix shell in general, so I really need some help. Here is my shell file. #!/bin/bash # Ask the user for their name echo What i

Pass variables from Jython (wsadmin) to shell script

Joey Cotter I'm trying to pass values retrieved from WebSphere to a Jython script invoked using wsadmin.sh to a variable in my invoker shell script. The caller shell script (getValue.sh) will have: #!/bin/sh /opt/ibm/WebSphere/AppServerV70/bin/wsadmin.sh -lan

Pass environment variables to shell script from Fastlane

Lorenzo B. I'm running Fastlane (a continuous build tool for iOS) to execute a custom shell script for decrypting files. This is an order. sh "./decrypt.sh ENV['ENCRYPTION_P12']" I can't figure out a way to pass environment variables to this script. Apparentl

Pass variables from shell script configuration file

Data mastery: I am going to write a shell script to install various services dynamically. I don't know much about shell scripting or Unix shell in general, so I really need some help. Here is my shell file. #!/bin/bash # Ask the user for their name echo What i

Pass variables from Jython (wsadmin) to shell script

Joey Cotter I'm trying to pass values retrieved from WebSphere to a Jython script called using wsadmin.sh to a variable in my caller shell script. The caller shell script (getValue.sh) will have: #!/bin/sh /opt/ibm/WebSphere/AppServerV70/bin/wsadmin.sh -lang

Pass variables from Python script to tcl shell

wolf 123 I'm new to this forum, so I apologize for any mistakes. I am trying to pass variables from my python code to a tcl script. The way I do it is: import os import Tkinter from Tkinter import * def set_impairments(port,delay): port=int(port) del

Pass environment variables to shell script from Fastlane

Lorenzo B. I'm running Fastlane (a continuous build tool for iOS) to execute a custom shell script for decrypting files. This is an order. sh "./decrypt.sh ENV['ENCRYPTION_P12']" I can't figure out a way to pass environment variables to this script. Apparentl

Pass variables from Jython (wsadmin) to shell script

Joey Cotter I'm trying to pass values retrieved from WebSphere to a Jython script called using wsadmin.sh to a variable in my caller shell script. The caller shell script (getValue.sh) will have: #!/bin/sh /opt/ibm/WebSphere/AppServerV70/bin/wsadmin.sh -lang

Pass environment variables to shell script from Fastlane

Lorenzo B. I'm running Fastlane (a continuous build tool for iOS) to execute a custom shell script for decrypting files. This is an order. sh "./decrypt.sh ENV['ENCRYPTION_P12']" I can't figure out a way to pass environment variables to this script. Apparentl

How to pass variables from awk to shell command?

Vahid Mirjalili I'm trying to run a shell command from awk for each line of a file that requires an input parameter. I tried to use system()but the input parameter is not recognized. Each line of this file is the address of a file that I want to run a command

How to pass variables from awk to shell command?

Vahid Mirjalili I'm trying to run a shell command from awk for each line of a file that requires an input parameter. I tried to use system()but the input parameter is not recognized. Each line of this file is the address of a file that I want to run a command

Pass variables from Jython (wsadmin) to shell script

Joey Cotter I'm trying to pass values retrieved from WebSphere to a Jython script called using wsadmin.sh to a variable in my caller shell script. The caller shell script (getValue.sh) will have: #!/bin/sh /opt/ibm/WebSphere/AppServerV70/bin/wsadmin.sh -lang

Pass variables from Java to shell script

call back I am trying to run a shell script from Java code. Currently, I am supplying the data manually in the script, but I would like to be able to supply the variables from the Java code running the script. Here is the Java code and script: public static vo

How to pass variables from shell script to .muttrc?

Amanda I want mutt( mutt-kz, actually - I'd love to migrate to, neomuttbut it's a bigger project) to get the SMTP password passso I don't have to store it in the config file in clear text, but I'm not sure how to correctly The password is passed to mine .muttr

Pass variables from shell script configuration file

Data mastery: I am going to write a shell script to install various services dynamically. I don't know much about shell scripting or Unix shell in general, so I really need some help. Here is my shell file. #!/bin/bash # Ask the user for their name echo What i

Pass variables from shell script configuration file

Data mastery: I am going to write a shell script to install various services dynamically. I don't know much about shell scripting or Unix shell in general, so I really need some help. Here is my shell file. #!/bin/bash # Ask the user for their name echo What i

Pass variables from Jython (wsadmin) to shell script

Joey Cotter I'm trying to pass values retrieved from WebSphere to a Jython script called using wsadmin.sh to a variable in my caller shell script. The caller shell script (getValue.sh) will have: #!/bin/sh /opt/ibm/WebSphere/AppServerV70/bin/wsadmin.sh -lang

Pass environment variables to shell script from Fastlane

Lorenzo B. I'm running Fastlane (a continuous build tool for iOS) to execute a custom shell script for decrypting files. This is an order. sh "./decrypt.sh ENV['ENCRYPTION_P12']" I can't figure out a way to pass environment variables to this script. Apparentl