0

I'm running through AWS CodePipeline tutorial and there is this step

saying that I have to create a jenkins job running bash script which will connect to the EC2 instance (not the one where jenkins is running, but the one where the code has been deployed earlier).

It is said that I have to connect to the EC2 instance by running this command in bash script:

TEST_IP_ADDRESS=192.168.0.4 rake test

But my gut feeling is saying that this step is completely wrong.

There is no variable with this name, and there is no option to connect to external instance just like that.

I've completed all the steps successfully, but this one is obviously wrong

matewilk
  • 1,191
  • 1
  • 13
  • 27
  • 1
    It seems to be setting an environment variable. Did you follow the instructions, including this one, and something subsequently failed? – jarmod Oct 24 '15 at 00:41
  • Yes indeed, I run the pipeline (or Jenkins job by it self) and Jenkins console log output is showing me that the command "rake test" is being executed on the instance where Jenkins is hosted, not on the one where code is deployed. And I suppose it should execute the command on the other instance according to the AWS tutorial. – matewilk Oct 24 '15 at 02:11

2 Answers2

0

The bash script will run in your jenkins instance, and it will make an HTTP request to the instance you configured in TEST_IP_ADDRESS.

When you add the "build step", and choose "Execute shell", you'll enter this:

TEST_IP_ADDRESS=192.168.0.4 rake test

You are defining the TEST_IP_ADDRESS variable, so it's up to you to give it an appropriate value.

tapichu
  • 305
  • 2
  • 6
  • Yes, this is clear, but the problem is that, there is no such a variable as TEST_IP_ADDRESS (on the list of jenkins variables), and it's never used. So the command is runs "rake test" on the jenkins server, not on the remote server as suggested in the tutorial. – matewilk Nov 02 '15 at 01:08
  • TEST_IP_ADDRESS is not a jenkins variable, it's an environment variable. When you add the build step of type "Execute shell", you'll type the command that should be executed (in one of your jenkins instances). As part of the command, you'll define the TEST_IP_ADDRESS variable: `TEST_IP_ADDRESS=192.168.0.4 rake test`. You have to enter the IP address of the remote server, but this does not mean that the command will execute on that server, it's just used to build the HTTP request URL. – tapichu Nov 03 '15 at 23:38
0

First I had the same confusion, then I saw the source code and it is pretty self-explained:

#!/usr/bin/env ruby

require 'net/http'
require 'minitest/autorun'
require 'socket'

class JenkinsSampleTest < MiniTest::Unit::TestCase
  def setup
    uri_params = {
      :host => ENV['TEST_IP_ADDRESS'] || 'localhost',
      :port => (ENV['TEST_PORT'] || '80').to_i,
      :path => '/index.html'
    }
    @webpage = Net::HTTP.get(URI::HTTP.build(uri_params))
  end

  def test_congratulations
    assert(@webpage =~ /Congratulations/)
  end
end
Liang
  • 403
  • 1
  • 5
  • 14