当前位置: 首页 > 知识库问答 >
问题:

Jenkins ansible插件找不到可执行的

充阳秋
2023-03-14

我在Amazon EC2上运行一个Jenkins--主机在一个Docker容器中,代理在一个单独的盒子中。我的playbook使用Jenkins Ansible插件执行Ansible脚本。

我不得不在代理上安装一个新版本的Ansible。我使用Running from Source指令从git安装了Ansible,并安装到/home/ec2-user/Ansible.如果我ssh到代理并运行Which Ansible,我将获得~/Ansible/bin/Ansible。我在Manage Jenkins>Global Tool Configuration页面的“Ansible可执行文件目录”中为我的新安装输入了/home/ec2-user/ansible/bin

然而,当我运行我的詹金斯管道时,我得到了这样的结果:

Running on docker-agent-1 in /home/ec2-user/jenkins/workspace/planet-healthcare-pipeline
[Pipeline] {
[Pipeline] pwd
[Pipeline] stage
[Pipeline] { (Download source and capture commit ID)
[Pipeline] sh
[planet-healthcare-pipeline] Running shell script
+ which ansible
which: no ansible in (/usr/local/bin:/bin:/usr/bin)

它说它运行在docker-agent-1(这是我的代理的名称)上,如果我在那里ssh,我可以看到Ansible。为什么詹金斯找不到ansible可执行文件?

更新:在添加PATH作为环境变量后,它可以找到Ansible,但现在其他一些东西中断了。以下是新的输出:

Running on docker-agent-1 in /home/ec2-user/jenkins/workspace/planet-healthcare-pipeline
[Pipeline] {
[Pipeline] pwd
[Pipeline] stage
[Pipeline] { (Download source and capture commit ID)
[Pipeline] sh
[planet-healthcare-pipeline] Running shell script
+ which ansible
/home/ec2-user/ansible/bin/ansible
[Pipeline] sh
[planet-healthcare-pipeline] Running shell script
+ ansible --version
ansible 2.2.0 (devel 1975a545bd) last updated 2016/09/20 16:19:06 (GMT +000)
  lib/ansible/modules/core: (detached HEAD 70d4ff8e38) last updated 2016/09/20 16:19:08 (GMT +000)
  lib/ansible/modules/extras: (detached HEAD db7a3f48e1) last updated 2016/09/20 16:19:09 (GMT +000)
  config file = /home/ec2-user/jenkins/workspace/planet-healthcare-pipeline/ansible.cfg
  configured module search path = Default w/o overrides
[Pipeline] git
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@bitbucket.org:planetgroup/planethealthcareportal.git # timeout=10
Fetching upstream changes from git@bitbucket.org:planetgroup/planethealthcareportal.git
 > git --version # timeout=10
using GIT_SSH to set credentials Deployment key for Planet Healthcare Portal
 > git fetch --tags --progress git@bitbucket.org:planetgroup/planethealthcareportal.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/develop^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/develop^{commit} # timeout=10
Checking out Revision e69608a15c9d433e2a22824c7e607048332a4160 (refs/remotes/origin/develop)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f e69608a15c9d433e2a22824c7e607048332a4160
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D develop # timeout=10
 > git checkout -b develop e69608a15c9d433e2a22824c7e607048332a4160
 > git rev-list e69608a15c9d433e2a22824c7e607048332a4160 # timeout=10
[Pipeline] sh
[planet-healthcare-pipeline] Running shell script
+ git rev-parse --verify HEAD
[Pipeline] readFile
[Pipeline] echo
Current commit ID: e69608a
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Copy application.yml to environment)
[Pipeline] withCredentials
[Pipeline] {
[Pipeline] sh
[planet-healthcare-pipeline] Running shell script
+ sudo cp **** config/application.yml
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build image)
[Pipeline] sh
[planet-healthcare-pipeline] Running shell script
+ docker build -t planethealthcare/portal_app .
Sending build context to Docker daemon 557.1 kB
Sending build context to Docker daemon 1.114 MB
Sending build context to Docker daemon 1.671 MB
Sending build context to Docker daemon 2.228 MB
Sending build context to Docker daemon 2.785 MB
Sending build context to Docker daemon 3.342 MB
Sending build context to Docker daemon 3.398 MB

Step 1 : FROM ruby:2.3
 ---> 7b66156f376c
Step 2 : MAINTAINER David Ham <dham@uxfactory.com>
 ---> Using cache
 ---> 47f6f577f049
Step 3 : RUN apt-get update && apt-get install -y     build-essential     curl     gstreamer1.0-plugins-base     gstreamer1.0-tools     gstreamer1.0-x     libqt5webkit5-dev     qt5-default     xvfb     && apt-get clean     && rm -rf /var/lib/apt/lists/*     && mkdir -p /app
 ---> Using cache
 ---> 38c1313e574d
Step 4 : WORKDIR /app
 ---> Using cache
 ---> 75a023d99fce
Step 5 : COPY Gemfile Gemfile.lock ./
 ---> Using cache
 ---> c39c81496a6b
Step 6 : ENV QMAKE /usr/bin/qmake
 ---> Using cache
 ---> 3226bf5f4e63
Step 7 : RUN bundle install --retry 20
 ---> Using cache
 ---> 91cb9908d53a
Step 8 : COPY . ./
 ---> 7330a8f5ba7c
Removing intermediate container bd55b7deddaf
Step 9 : EXPOSE 3000
 ---> Running in 76e6418e2b3f
 ---> 81427ffb31f5
Removing intermediate container 76e6418e2b3f
Step 10 : CMD bundle exec rails server
 ---> Running in c2a90c3c59f6
 ---> 15ab02b3ab8d
Removing intermediate container c2a90c3c59f6
Successfully built 15ab02b3ab8d
[Pipeline] dockerFingerprintFrom
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Run test suite)
[Pipeline] sh
[planet-healthcare-pipeline] Running shell script
+ docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=phc_portal_test postgres:9.5
[Pipeline] dockerFingerprintRun
[Pipeline] sh
[planet-healthcare-pipeline] Running shell script
+ docker inspect -f . planethealthcare/portal_app
.
[Pipeline] withDockerContainer
$ docker run -t -d -u 500:500 --link 85511ce90ce11c24818ae63bbbf7ab47745be7d96807d450b4adebd4c3196c5e:postgres -p 3000:3000 -e RAILS_ENV=test -w /home/ec2-user/jenkins/workspace/planet-healthcare-pipeline -v /home/ec2-user/jenkins/workspace/planet-healthcare-pipeline:/home/ec2-user/jenkins/workspace/planet-healthcare-pipeline:rw -v /home/ec2-user/jenkins/workspace/planet-healthcare-pipeline@tmp:/home/ec2-user/jenkins/workspace/planet-healthcare-pipeline@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat planethealthcare/portal_app
[Pipeline] {
[Pipeline] echo
running tests...
[Pipeline] sh
[planet-healthcare-pipeline] Running shell script
+ rails db:migrate
/home/ec2-user/jenkins/workspace/planet-healthcare-pipeline@tmp/durable-32785ba4/script.sh: 2: /home/ec2-user/jenkins/workspace/planet-healthcare-pipeline@tmp/durable-32785ba4/script.sh: rails: not found
[Pipeline] }
$ docker stop 3acf37726ce1061d2e0f6e8d0cec882c707b42e710916636b17aaece4f516f2d
$ docker rm -f 3acf37726ce1061d2e0f6e8d0cec882c707b42e710916636b17aaece4f516f2d
[Pipeline] // withDockerContainer
[Pipeline] sh
[planet-healthcare-pipeline] Running shell script
+ docker stop 85511ce90ce11c24818ae63bbbf7ab47745be7d96807d450b4adebd4c3196c5e
85511ce90ce11c24818ae63bbbf7ab47745be7d96807d450b4adebd4c3196c5e
+ docker rm -f 85511ce90ce11c24818ae63bbbf7ab47745be7d96807d450b4adebd4c3196c5e
85511ce90ce11c24818ae63bbbf7ab47745be7d96807d450b4adebd4c3196c5e
[Pipeline] }
[Pipeline] // stage
[Pipeline] mail
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
node('docker') {
    currentBuild.result = "SUCCESS"

    try{
        def git_commit = ""
        def workspace = pwd()
        def APPLICATION_YML
        def image

        stage("Download source and capture commit ID") {
            sh "which ansible"
            sh "ansible --version"


            // Download source
            git branch: 'develop', credentialsId: 'b96345a1-543c-4ccd-9a86-deca7203625c', url: 'git@bitbucket.org:planetgroup/planethealthcareportal.git'

            // Get the commit ID
            sh 'git rev-parse --verify HEAD > GIT_COMMIT'
            git_commit = readFile('GIT_COMMIT').take(7)
            echo "Current commit ID: ${git_commit}"
        }

        stage("Copy application.yml to environment"){
            // write the application.yml to a file
            withCredentials([[$class: 'FileBinding', credentialsId: '67dbd2e7-008f-4463-89a6-9645060e8ec8', variable: 'APPLICATION_YML']]) {
                sh "sudo cp ${env.APPLICATION_YML} config/application.yml"
            }
        }

        stage("Build image"){
            image = docker.build "planethealthcare/portal_app"
        }

        stage("Run test suite"){
            // start postgres
            def postgres95 = docker.image('postgres:9.5')
            postgres95.withRun("-p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=phc_portal_test"){ postgres ->
                image.inside("--link ${postgres.id}:postgres -p 3000:3000 -e RAILS_ENV=test") {
                    echo "running tests..."
                    sh "rails db:migrate"
                    sh "rspec --tag ~pending"
                    sh "cucumber"
                }
            }
        }

        stage("Push to ECR registry"){
            docker.withRegistry('https://0000000000.dkr.ecr.us-east-1.amazonaws.com', 'ecr:dham'){
                image.push "${git_commit}"
                image.push 'latest'
            }
        }

        stage("Deploy app"){
            // run the playbook
            ansiblePlaybook([
              colorized: true,
              credentialsId: 'planet-healthcare',
              installation: 'ansible-2-2-0',
              inventory: 'staging',
              playbook: 'deploy.yml',
              extras: "--extra-vars 'app_build_id=${git_commit}''"
            ])
        }
    }

    catch(err) {
        currentBuild.result = "FAILURE"

        mail body: "project build error: ${err}\n\n\n ${currentBuild.description}" ,
        subject: 'project build failed',
        to: 'me@example.com'

        throw err
    }

}

它在“run test Suite”阶段失败了--它找不到rails来运行rails db:migrate,尽管我知道它在容器中。

为什么在代理上设置路径会影响在Docker容器中发生的脚本?

共有1个答案

锺星腾
2023-03-14

您是否在脚本中执行哪个Ansible?它只搜索已定义的路径。
而且/home/ec2-user/ansible/bin似乎不在/usr/local/bin://bin://usr/bin中(从您的输出)。
您可以转到Jenkins中的代理节点设置,并添加path环境变量$path://home/ec2-user/ansible/bin值。

 类似资料:
  • 问题内容: 我在安装psycopg2时遇到问题。我尝试执行以下操作时收到以下错误pip install psycopg2: 但是问题出在我身上PATH; 它运行没有任何问题: 我尝试将径添加到文件中,并使用从其网站(http://initd.org/psycopg/)下载的源文件进行构建,然后收到以下错误消息! 但实际上是那里!!! 这些错误使我感到困惑。有人可以帮忙吗? 顺便说一下,我sudo所

  • 我有独立的应用程序,它绑定在可执行的中。在可执行的清单文件中,有一个class-path条目,其中列出了所有依赖的(包括所有的日志实现jar)。这个可执行jar还包含文件。 使用这种结构,当我使用简单的命令运行应用程序时,应用程序在正确的日志记录下运行良好。但这里的主要问题是,要更改日志级别,需要打开jar文件,而我不能要求客户端这样做。所以我将放在了jar外部,但现在所有日志记录都发生在控制台上

  • 问题内容: 我在Windows 7上运行Python3.4。我试图将Python接口用于graphviz。这是我打算运行的脚本: 我在运行时收到以下错误: 现在,我确定我已经正确安装了正确的依赖项。我首先尝试设置正确的环境变量。graphviz可执行文件位于 C:\ Program Files(x86)\ Graphviz2.37 \ bin, 因此我转到了“环境变量”部分。有两个部分:用户变量和

  • 我在Windows7上运行Python3.4。我正在尝试使用GraphViz的Python接口。这是我打算运行的脚本: 然后,按照这里给出的答案,我卸载了pydot(实际上我在这里使用pydotplus),并重新安装了它,但仍然没有成功。 我已经尝试了几个小时来解决这个问题,整个路径变量的事情只是令人困惑和沮丧。

  • 问题内容: 我在程序中使用以下代码来加载属性文件: 该代码在Eclipse中运行良好。然后,将程序打包到一个名为MyProgram.jar的JAR中,然后运行它,第二行得到了NullPointerException。JAR不包含属性文件,它们都位于同一目录中。我正在使用Maven创建JAR。我该如何解决这个问题? 更新:我不想将属性文件添加到JAR中,因为它将在部署时创建。 问题答案: Balus

  • 我有一个docker映像,它安装了,但是当我试图运行它时,我得到了一个错误: 如果我在交互模式下运行bash,则可用。 我做错了什么? 这是我的Dockerfile: