(我知道这个问题已经问过几次了,这篇文章是我尝试了所有以前的答案而仍然失败的结果)
我正在尝试在詹金斯(Jenkins)建立管道。在我的Jenkinsfile中,有一个阶段:
stage('Install dependencies') {
steps {
echo 'Starting Build'
sh 'echo $PATH; pip3 install -r requirements.txt'
}
}
此阶段不断出现日志失败:
[2020-06-12T16:02:29.457Z] + PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin:/usr/local/bin
[2020-06-12T16:02:29.457Z] + pip3 install -r requirements.txt
[2020-06-12T16:02:29.457Z] /var/jenkins_home/workspace/CD4MLScenarios_master@tmp/durable-e59fe630/script.sh:
line 1: pip3: not found
script returned exit code 127
我尝试了许多不同的操作,但都以相同的错误结束:
sudo easy_install pip3
withEnv(["HOME=${env.WORKSPACE}"])
PATH=${PATH}:/usr/local/bin;
当我尝试python3 -m pip install -r requirements.txt
时收到错误消息:
[2020-06-12T16:55:33.239Z] + python3 -m pip install -r requirements.txt
[2020-06-12T16:55:33.239Z] /var/jenkins_home/workspace/CD4M-Scenarios_master@tmp/durable-9c155103/script.sh:
line 1: python3: not found
script returned exit code 127
如果这完全有用,这是我用来启动Jenkins容器的docker命令:
docker container run --name jenkins-tutorial --rm --detach
--network jenkins
--env DOCKER_HOST=tcp://docker:2376
--env DOCKER_CERT_PATH=/certs/client -
-env DOCKER_TLS_VERIFY=1
--volume jenkins-data:/var/jenkins_home
--volume jenkins-docker-certs:/certs/client:ro
--volume "$HOME":/home --publish 8080:8080 jenkinsci/blueocean
答案 0 :(得分:1)
您可能正在容器中运行Jenkins。 Jenkins容器未安装python
,因为运行Jenkins并不需要安装python
,并且容器在设计上仅包含必要的最少内容。
此外,您正在Jenkins master上运行您的工作,因此它与Jenkins(Jenkins容器)在同一位置运行,因此没有pip
也没有easy_install
也没有python
。
您应该在安装了pip
和python
的地方运行作业。您可能需要考虑在pipeline {
agent {
docker { image 'python:3' }
}
stages {
stage('Test') {
steps {
sh 'pip --version'
}
}
}
}
容器中运行作业,例如像这样:
import folium
import pandas as pd
import numpy as np
import osmnx as ox
import networkx as nx
import os
ox.config(use_cache=True, log_console=True)
G = ox.graph_from_point((-33.889606, 151.283306), distance=3000, network_type='drive')
G = ox.speed.add_edge_speeds(G)
G = ox.speed.add_edge_travel_times(G)
orig = ox.get_nearest_node(G, (-33.889606, 151.283306))
dest = ox.get_nearest_node(G, (-33.862004, 151.211151))
route = nx.shortest_path(G, orig, dest, 'travel_time')
route_map = ox.plot_route_folium(G, route)
route_map.save('route_333.html')
这将运行一个新容器(官方python3发布容器)并在该容器内执行步骤。