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
        '''
    }
  }
}}

May 1, 2018 in Jenkins by Atul
• 10,240 points
3,012 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
• 7,340 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
• 18,520 points
36,480 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
• 7,060 points
5,679 views
0 votes
1 answer
0 votes
1 answer
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,059 views
+2 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
• 7,340 points
1,801 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
• 7,060 points
6,882 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP