Not getting any output through sh 'alias' for Jenkinsfile

0 votes

I have a docker container which runs Jenkins.

I have define an alias and print this alias in a jekinsfile.

I also tried manually to  connect with Jenkins container, and I did it:

alias foo='bar'
when I execute the same thing in Jenkinsfile, foo command won't respond

the pipeline code is written below:

#!/bin/groovy

pipeline {
agent any
stages {
  stage("Use alias command"){
    steps { 
        sh '''
          alias foo="bar"
          foo
        '''
    }
  }
}}

Apr 30, 2018 in Jenkins by Atul
• 10,240 points
442 views

1 answer to this question.

0 votes

As you know each sh command runs in it's own shell. It has same location as agent/workspace, but since it's a new shell, environment variables, aliases, etc, can be lost.So combine the lines into a single sh:

#!/bin/groovy

pipeline {
agent any
stages {
  stage("Use alias command"){
    steps { 
        sh '''
          alias foo="bar"
          foo
        '''
    }
  }
}}
I hope it would help you resolve your query.
answered May 1, 2018 by shubham
• 6,890 points

Related Questions In Jenkins

+4 votes
7 answers

How to set the pipeline name and description for a Jenkinsfile?

You can rename pipeline jobs in jenkins ...READ MORE

answered Oct 11, 2018 in Jenkins by Hannah
• 16,220 points
8,188 views
0 votes
1 answer

Jenkins console output not in realtime

Make sure your script is flushing it ...READ MORE

answered Aug 7, 2018 in Jenkins by Nilesh
• 6,880 points
1,147 views
+5 votes
4 answers

How can I run a Jenkinsfile from a particular folder?

Consider the below points: The Freestyle project ...READ MORE

answered Mar 26, 2018 in Jenkins by anonymous
4,284 views
0 votes
1 answer

any way to integrate Jenkins with ServiceNow?

Now, there is no official servicenow support ...READ MORE

answered Apr 10, 2018 in Jenkins by DareDev
• 6,810 points
1,283 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
210 views
0 votes
1 answer
0 votes
1 answer

Why is it displaying Jenkins build failure for Android app

I think you should try this. Try Uninstalling ...READ MORE

answered Apr 12, 2018 in Jenkins by shubham
• 6,890 points
259 views
0 votes
2 answers

Is possible for Jenkins to auto start and stop slave nodes?

Try Jenkins Plugin called as Slave SetupPlugin. This ...READ MORE

answered Aug 6, 2018 in Jenkins by Nilesh
• 6,880 points
1,049 views