Unable to use aws cli from Jenkins Groovy












0















I am trying to write Jenkins post-initialisation scripts in Groovy that use the AWS CLI. My Jenkins lives behind a corporate proxy, and I configured it as myproxy port 3128 with a username and password, and a no_proxy of "10.*.*.*,ap-southeast-2.compute.internal,localhost,127.0.0.1,myothernoproxydomains.com".



The Groovy code I am trying is as follows:



def sg = "curl http://169.254.169.254/latest/meta-data/security-groups".execute().text
"aws ec2 describe-security-groups
--region ap-southeast-2
--filters Name=group-name,Values=${sg}
--query SecurityGroups[0].GroupId
--output text".execute().text


If I comment out the second command, and run it in the Jenkins Script console, it runs fine and I can print the security group name. But if I allow the second command to run, I eventually get a message from my Chrome browser,




This page isn't working", myjenkins.mydomain.com took too long to respond. HTTP ERROR 504.




The Jenkins has no trouble using the HTTP proxy in other contexts, e.g. downloading packages, plugins etc.



I note that environment variables relating to the HTTP proxy do not appear in System.genenv:



System.getenv()
Result: {PATH=/sbin:/usr/sbin:/bin:/usr/bin, SHELL=/bin/bash, LOGNAME=jenkins, PWD=/, USER=jenkins, LANG=en_US.UTF-8, SHLVL=2, HOME=/var/lib/jenkins, _=/etc/alternatives/java}


I have seen Groovy code that calls the AWS CLI work on other Jenkinses at other sites. I think it might be somehow proxy-related?



Am I doing anything wrong? Any ideas on what the issue could be?










share|improve this question





























    0















    I am trying to write Jenkins post-initialisation scripts in Groovy that use the AWS CLI. My Jenkins lives behind a corporate proxy, and I configured it as myproxy port 3128 with a username and password, and a no_proxy of "10.*.*.*,ap-southeast-2.compute.internal,localhost,127.0.0.1,myothernoproxydomains.com".



    The Groovy code I am trying is as follows:



    def sg = "curl http://169.254.169.254/latest/meta-data/security-groups".execute().text
    "aws ec2 describe-security-groups
    --region ap-southeast-2
    --filters Name=group-name,Values=${sg}
    --query SecurityGroups[0].GroupId
    --output text".execute().text


    If I comment out the second command, and run it in the Jenkins Script console, it runs fine and I can print the security group name. But if I allow the second command to run, I eventually get a message from my Chrome browser,




    This page isn't working", myjenkins.mydomain.com took too long to respond. HTTP ERROR 504.




    The Jenkins has no trouble using the HTTP proxy in other contexts, e.g. downloading packages, plugins etc.



    I note that environment variables relating to the HTTP proxy do not appear in System.genenv:



    System.getenv()
    Result: {PATH=/sbin:/usr/sbin:/bin:/usr/bin, SHELL=/bin/bash, LOGNAME=jenkins, PWD=/, USER=jenkins, LANG=en_US.UTF-8, SHLVL=2, HOME=/var/lib/jenkins, _=/etc/alternatives/java}


    I have seen Groovy code that calls the AWS CLI work on other Jenkinses at other sites. I think it might be somehow proxy-related?



    Am I doing anything wrong? Any ideas on what the issue could be?










    share|improve this question



























      0












      0








      0








      I am trying to write Jenkins post-initialisation scripts in Groovy that use the AWS CLI. My Jenkins lives behind a corporate proxy, and I configured it as myproxy port 3128 with a username and password, and a no_proxy of "10.*.*.*,ap-southeast-2.compute.internal,localhost,127.0.0.1,myothernoproxydomains.com".



      The Groovy code I am trying is as follows:



      def sg = "curl http://169.254.169.254/latest/meta-data/security-groups".execute().text
      "aws ec2 describe-security-groups
      --region ap-southeast-2
      --filters Name=group-name,Values=${sg}
      --query SecurityGroups[0].GroupId
      --output text".execute().text


      If I comment out the second command, and run it in the Jenkins Script console, it runs fine and I can print the security group name. But if I allow the second command to run, I eventually get a message from my Chrome browser,




      This page isn't working", myjenkins.mydomain.com took too long to respond. HTTP ERROR 504.




      The Jenkins has no trouble using the HTTP proxy in other contexts, e.g. downloading packages, plugins etc.



      I note that environment variables relating to the HTTP proxy do not appear in System.genenv:



      System.getenv()
      Result: {PATH=/sbin:/usr/sbin:/bin:/usr/bin, SHELL=/bin/bash, LOGNAME=jenkins, PWD=/, USER=jenkins, LANG=en_US.UTF-8, SHLVL=2, HOME=/var/lib/jenkins, _=/etc/alternatives/java}


      I have seen Groovy code that calls the AWS CLI work on other Jenkinses at other sites. I think it might be somehow proxy-related?



      Am I doing anything wrong? Any ideas on what the issue could be?










      share|improve this question
















      I am trying to write Jenkins post-initialisation scripts in Groovy that use the AWS CLI. My Jenkins lives behind a corporate proxy, and I configured it as myproxy port 3128 with a username and password, and a no_proxy of "10.*.*.*,ap-southeast-2.compute.internal,localhost,127.0.0.1,myothernoproxydomains.com".



      The Groovy code I am trying is as follows:



      def sg = "curl http://169.254.169.254/latest/meta-data/security-groups".execute().text
      "aws ec2 describe-security-groups
      --region ap-southeast-2
      --filters Name=group-name,Values=${sg}
      --query SecurityGroups[0].GroupId
      --output text".execute().text


      If I comment out the second command, and run it in the Jenkins Script console, it runs fine and I can print the security group name. But if I allow the second command to run, I eventually get a message from my Chrome browser,




      This page isn't working", myjenkins.mydomain.com took too long to respond. HTTP ERROR 504.




      The Jenkins has no trouble using the HTTP proxy in other contexts, e.g. downloading packages, plugins etc.



      I note that environment variables relating to the HTTP proxy do not appear in System.genenv:



      System.getenv()
      Result: {PATH=/sbin:/usr/sbin:/bin:/usr/bin, SHELL=/bin/bash, LOGNAME=jenkins, PWD=/, USER=jenkins, LANG=en_US.UTF-8, SHLVL=2, HOME=/var/lib/jenkins, _=/etc/alternatives/java}


      I have seen Groovy code that calls the AWS CLI work on other Jenkinses at other sites. I think it might be somehow proxy-related?



      Am I doing anything wrong? Any ideas on what the issue could be?







      jenkins






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 5:30







      Alex Harvey

















      asked Nov 13 '18 at 4:28









      Alex HarveyAlex Harvey

      4,0191823




      4,0191823
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I think the issue is that the call to 169.254.169.254 is not passing through the proxy, so the CLI isn't timing out it is the AWS call to the meta data store. Add that into your NO_PROXY value and hopefully that should resolve the issue.



          The other option is to turn off the proxy, they are evil :)






          share|improve this answer
























          • The proxy certainly is evil, but adding 169.254.169.254 to no_proxy did not fix the issue unfortunately.

            – Alex Harvey
            Nov 13 '18 at 5:30













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273816%2funable-to-use-aws-cli-from-jenkins-groovy%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I think the issue is that the call to 169.254.169.254 is not passing through the proxy, so the CLI isn't timing out it is the AWS call to the meta data store. Add that into your NO_PROXY value and hopefully that should resolve the issue.



          The other option is to turn off the proxy, they are evil :)






          share|improve this answer
























          • The proxy certainly is evil, but adding 169.254.169.254 to no_proxy did not fix the issue unfortunately.

            – Alex Harvey
            Nov 13 '18 at 5:30


















          0














          I think the issue is that the call to 169.254.169.254 is not passing through the proxy, so the CLI isn't timing out it is the AWS call to the meta data store. Add that into your NO_PROXY value and hopefully that should resolve the issue.



          The other option is to turn off the proxy, they are evil :)






          share|improve this answer
























          • The proxy certainly is evil, but adding 169.254.169.254 to no_proxy did not fix the issue unfortunately.

            – Alex Harvey
            Nov 13 '18 at 5:30
















          0












          0








          0







          I think the issue is that the call to 169.254.169.254 is not passing through the proxy, so the CLI isn't timing out it is the AWS call to the meta data store. Add that into your NO_PROXY value and hopefully that should resolve the issue.



          The other option is to turn off the proxy, they are evil :)






          share|improve this answer













          I think the issue is that the call to 169.254.169.254 is not passing through the proxy, so the CLI isn't timing out it is the AWS call to the meta data store. Add that into your NO_PROXY value and hopefully that should resolve the issue.



          The other option is to turn off the proxy, they are evil :)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 4:59









          mransleymransley

          428511




          428511













          • The proxy certainly is evil, but adding 169.254.169.254 to no_proxy did not fix the issue unfortunately.

            – Alex Harvey
            Nov 13 '18 at 5:30





















          • The proxy certainly is evil, but adding 169.254.169.254 to no_proxy did not fix the issue unfortunately.

            – Alex Harvey
            Nov 13 '18 at 5:30



















          The proxy certainly is evil, but adding 169.254.169.254 to no_proxy did not fix the issue unfortunately.

          – Alex Harvey
          Nov 13 '18 at 5:30







          The proxy certainly is evil, but adding 169.254.169.254 to no_proxy did not fix the issue unfortunately.

          – Alex Harvey
          Nov 13 '18 at 5:30




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273816%2funable-to-use-aws-cli-from-jenkins-groovy%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation