Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29544

get address of an EC2 agent from a Jenkins pipeline for git push/scp?

$
0
0

I'm setting up a simple Jenkins pipeline, with a stage running on an AWS EC2 agent.

pipeline {
  agent none 
  stages {
    stage('Prepare') {
      agent { label 'master' }
      steps {
        sh "touch somefile"
        stash includes: "somefile", name:"ARTIFACT"
      }
    }
    stage('AWS') {
      agent { label 'aws' }
      steps {
        unstash 'ARTIFACT'
        sh "cat somefile"
      }
    }
  }
}

Stash/unstash works for simple files, but ideally I'd like direct ssh connection so that I can push a git repo onto the slave, and maybe scp a directory. My simple issue is I don't know the public DNS/IP of the slave started by the EC2 plugin so can't connect.

I guess I could figure that out via extra scripts and installing AWS CLI on my Jenkins boxes. Also I've seen suggestions to use S3 and CodeDeploy to push anything onto the instances..however this seems more convoluted than I want at least initially.

I've also seen hints to use instance metadata and http requests to get the IP/DNS ( https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html#configuring-instance-metadata-options ) - again looks way more complicated than I'd expect (maybe because I'm a newbie on aws;), so I think/hope I'm not on the right track there.

Was also thinking of adding an extra stage on the aws agent, just to login and do something like "ip addr show" , and pass that back to the pipeline so that a subsequent step could use that for "git push" or scp, etc..

I would have assumed the Jenkins EC2 plugin already knows the IP/DNS to the slave otherwise it couldn't connect itself.

So it would be great to hear about a more straightforward and robust solution.


Viewing all articles
Browse latest Browse all 29544

Trending Articles