无法在Jenkins管道中安装Psycopg2

时间:2017-07-10 08:53:29

标签: python jenkins jenkins-pipeline psycopg2

我在CentOS 6上使用Jenkins Pipeline,我想在这个Jenkins管道作业中安装python 3.5依赖项。

我的声明性管道是,

pipeline {
    agent any

    stages {
        stage('InstallPythonDeps') {
            steps {
                sh "./InstallPythonDeps.sh"
            }
        }
    }
}

InstallPythonDeps.sh是,

export PATH=$PATH:/usr/pgsql-9.3/bin
# I uses pyenv, pyenv-virtualenv
sudo /var/lib/jenkins/.pyenv/versions/my-virtualenv/bin/pip install -r requirements.txt
echo $PATH
which pg_config

但是当我使用Error: pg_config executable not found.安装psycopg2时,我仍然看到了pip消息,尽管如此,

  • echo $PATH的结果为/sbin:/usr/sbin:/bin:/usr/bin:/usr/pgsql-9.3/bin
  • which pg_config的结果为/usr/pgsql-9.3/bin/pg_config

yum libs,

$ sudo yum list installed | grep postgresql
postgresql93.x86_64                9.3.16-1PGDG.rhel6            @pgdg93
postgresql93-devel.x86_64          9.3.16-1PGDG.rhel6            @pgdg93
postgresql93-libs.x86_64           9.3.16-1PGDG.rhel6            @pgdg93
postgresql93-server.x86_64         9.3.16-1PGDG.rhel6            @pgdg93

$ sudo yum list installed | grep python-devel
python-devel.x86_64                2.6.6-66.el6_8                @updates

我不明白为什么在pg_config时找不到pip install。我做错了什么?

1 个答案:

答案 0 :(得分:0)

自己回答,

我将InstallPythonDeps脚本更改为

export PATH=$PATH:/usr/pgsql-9.3/bin

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

pyenv activate psapi
pip install -r requirements.txt

但我不确切知道为什么要这样做......