简体   繁体   中英

aws eks command not recognized using Jenkins pipeline

I have created a EC2 instance where Jenkins is running connected to my GitHub account. The following are the two steps of my Jenkins pipeline:

pipeline {
    agent any
    stages {
        stage('Kubernetes cluster') {
            steps {
                withAWS(region:'us-west-2', credentials:'aws-kubernetes') {
                    sh '''
                    if [ ! aws cloudformation describe-stacks --region us-west-2 --stack-name eksctl-EmaJarK8sCluster-cluster ] ; then

                        if [ ! aws cloudformation describe-stacks --region us-west-2 --stack-name eksctl-EmaJarK8sCluster-nodegroup-standard-workers ] ; then

                            eksctl create cluster \
                            --name EmaJarK8sCluster \
                            --version 1.13 \
                            --nodegroup-name standard-workers \
                            --node-type t2.small \
                            --nodes 2 \
                            --nodes-min 1 \
                            --nodes-max 3 \
                            --node-ami auto \
                            --region us-west-2 \
                            --zones us-west-2a \
                            --zones us-west-2b \
                            --zones us-west-2c \

                        fi

                    fi
                    '''
                }
            }
        }

        stage('Configuration file cluster') {
            steps {
                withAWS(region:'us-west-2', credentials:'aws-kubernetes') {
                    sh '''
                        aws eks --region us-west-2 update-kubeconfig --name EmaJarK8sCluster
                    '''
                }
            }
        }
    }
}

The first step creates a Kubernetes cluster if it doesn't exist, the second one creates a configuration file for that cluster. This step works pretty well and creates two cloudformation stacks and one EC2 machine where the Kubernetes cluster is running.

The second stage fails with the following error:

Invalid choice: 'eks', maybe you meant:

  * es

After reading a couple of tutorial I've found out that I needed to update awscli to version 1.18.57 in order to have the eks command available. So I've logged into my Jenkins machine (not the one dedicated to the k8s cluster) ad I've update the awscli . Unfortunately this is not enough. I still get the same error. I can run the command manually into Jenkins the machine but, for some reason, I cannot run it via Jenkins pipeline.

Can someone help me with this problem?

Thanks in advance.

Can you provide the full path to the aws command? Also add which aws and aws --version to the second stage script, and confirm that output.

The above should highlight the actual path of the command, and the current version. Correct your configuration as needed.

Are you updated jenkins agents?

If not:

Upgrading Windows Service Wrapper

  1. Upgrade Jenkins to the version, which provides this module
  2. Jenkins is expected to automatically upgrade jenkins-slave.exe executables
  3. If the upgrade happens, you should be able to see the message in the Agent log in Jenkins Web UI
  4. Once upgrade is done, the changes will be applied on the next Windows service restart

Unfortunately the solutions provided didn't work for me. My goal was to setup an machine where I could run a Kubernetes environment in order to implement a blue/green deployment. The deployment had to be handled using Jenkins so I had to create a dedicated machine for Jenkins itself.

I followed this guide to set up all the dependencies: https://medium.com/faun/learning-kubernetes-by-doing-part-1-setting-up-eks-in-aws-50dcf7a76247

The mistake that I made before was to install all those dependencies using brew . This caused many problems and polluted my PATH environment variable. I solved it terminating the machine and creating a new instance. In this case I installed the dependencies manually or using apt-get.

The resources I had to install:

  • AWS CLI
  • IAM-AWS-AUTHENTICATOR
  • Docker
  • eksctl

A couple of notes:

  • Be sure to install eksctl version 0.19.0 as reported here
  • If you get the error "aws-iam-authenticator": executable file not found in $PATH be sure to install aws-iam-authenticator following this guide

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM