Я создал псевдоним как часть моего образа докера и поместил команду в ~ / .bashrc.Псевдоним действительно прост.Просто нужно запустить скрипт, который был установлен во время сборки образа.Когда я запустил док-контейнер на своем локальном компьютере, я смог увидеть псевдоним.Также в конвейере jenkins, когда я запускал кошку bashrc, я мог видеть команду псевдонима.Это мой dockerfile.
FROM ros:melodic-ros-core-stretch
RUN apt-get update
COPY ./scripts /scripts
RUN cat scripts/alias.sh > ~/.bashrc
RUN bash scripts/install-tools.bash
Вот так выглядит install-tools.bash.
#!/bin/bash
mkdir -p /opt/scripts
install --mode=755 --group=root --owner=root /scripts/pre-build.bash /opt/scripts/
rm -rf /scripts
Вот так выглядит alias.sh.
alias pre-build="bash /opt/scripts/pre-build.bash"
Вот так выглядит файл Jenkinsfile.
pipeline {
agent {
docker {
args '--network host -u root:root'
image <private repo from dockerhub>
registryCredentialsId 'docker-credentials'
registryUrl 'https://registry.hub.docker.com'
}
}
stages {
stage ('Test') {
steps {
sh '''#!/bin/bash
pre-build
'''
}
}
}
post {
always {
cleanWs()
}
}
}
Это ошибка, которую я получаю от Дженкинса.
Started by user Automated Build Environment
Obtained Jenkinsfile from git https://github.com/<Organization>/test_pkg
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/test_pkg
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential 205a054c-54a3-4cb3-9a7f-519516cc3050
Cloning the remote Git repository
Cloning repository https://github.com/<Organization>/test_pkg
> git init /var/lib/jenkins/workspace/test_pkg # timeout=10
Fetching upstream changes from https://github.com/<Organization>/test_pkg
> git --version # timeout=10
using GIT_ASKPASS to set credentials
> git fetch --tags --progress https://github.com/<Organization>/test_pkg +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url https://github.com/<Organization>/test_pkg # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url https://github.com/<Organization>/test_pkg # timeout=10
Fetching upstream changes from https://github.com/<Organization>/test_pkg
using GIT_ASKPASS to set credentials
> git fetch --tags --progress https://github.com/<Organization>/test_pkg +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 514613afaf7c8be82bd20e219c062f7a4b3fb733 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 514613afaf7c8be82bd20e219c062f7a4b3fb733
Commit message: "Update Jenkinsfile"
> git rev-list --no-walk 8c840617b0aed9ae50d00700192ed3573bb1c0d4 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withDockerRegistry
$ docker login -u <private docker hub username> -p ******** https://registry.hub.docker.com
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /var/lib/jenkins/workspace/test_pkg@tmp/98982a2f-21bf-4460-9dab-d13f8ddba164/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . <private docker hub repo>
Error: No such object: <private docker hub repo>
[Pipeline] sh
+ docker inspect -f . registry.hub.docker.com/<private docker hub repo>
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 125:130 --network host -u root:root -w /var/lib/jenkins/workspace/test_pkg -v /var/lib/jenkins/workspace/test_pkg:/var/lib/jenkins/workspace/test_pkg:rw,z -v /var/lib/jenkins/workspace/test_pkg@tmp:/var/lib/jenkins/workspace/test_pkg@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** registry.hub.docker.com/<private docker hub repo> cat
$ docker top 657db353b9e3249c87468eafdeae64246f6b2b1ebeb1cd5ed00c618fc8f1691c -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] sh
/var/lib/jenkins/workspace/test_pkg@tmp/durable-e7036032/script.sh: line 2: pre-build: command not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] cleanWs
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] done
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 657db353b9e3249c87468eafdeae64246f6b2b1ebeb1cd5ed00c618fc8f1691c
$ docker rm -f 657db353b9e3249c87468eafdeae64246f6b2b1ebeb1cd5ed00c618fc8f1691c
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
Я пытаюсь выяснить, как добавить псевдонимы.к образу докера, к которому я могу получить доступ в Jenkinsfile при выполнении декларативного конвейера.