Code Monkey home page Code Monkey logo

Comments (5)

MarkEWaite avatar MarkEWaite commented on September 13, 2024

Thanks for the report @WilliamShoww .

I'm not sure of the best way to describe using the plugin with Pipeline, since it is not specific to Pipeline. Here is an example that I use to test the plugin.

The following Pipeline job uses an agent with the 'alpine' label defined on my controller.

pipeline {
    agent {
        label 'alpine'
    }
    stages {
        stage('Hello from Alpine docker agent') {
            steps {
                sh 'whoami && uname -a && cat /etc/os-release && java -version && git --version'
            }
        }
    }
}

All agents with the label 'alpine' on my controller are started by the docker plugin when requested, then stopped by the docker plugin when the job completes. When I ran that job, the console output reported:

Started by user Mark Waite
[Pipeline] Start of Pipeline
[Pipeline] node
Running on alpine-jdk21-00048adis7zag on mark-pc2 in /home/jenkins/agent/workspace/alpine-whoami
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Hello from Alpine docker agent)
[Pipeline] sh
+ whoami
jenkins
+ uname -a
Linux abf179eeac7d 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May  7 09:00:52 UTC 2 x86_64 Linux
+ cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.19.1
PRETTY_NAME="Alpine Linux v3.19"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
+ java -version
openjdk version "21.0.3" 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode)
+ git --version
git version 2.43.0
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[Gitea] do not publish assets due to source being no GiteaSCMSource
Finished: SUCCESS

In the configuration as code definition for my Jenkins controller, I have the following entry:

jenkins:
  clouds:
  - docker:
      containerCap: 3
      dockerApi:
        connectTimeout: 23
        dockerHost:
          uri: "tcp://docker-host.markwaite.net:2375"
        readTimeout: 43
      errorDuration: 313
      name: "mark-pc2"
      templates:
      - connector:
          jnlp:
            jenkinsUrl: "http://mark-pc2.markwaite.net}:8080/"
            user: "1000"
        dockerTemplateBase:
          cpuPeriod: 0
          cpuQuota: 0
          image: "jenkins/inbound-agent:3248.v65ecb_254c298-2-alpine-jdk21"
        labelString: "alpine jdk21 alpine-jdk21 git-2.43"
        name: "alpine-jdk21"
        pullTimeout: 171
        remoteFs: "/home/jenkins/agent"

That configuration as code entry describes the agent definition for the 'alpine' label.

Does that help answer your question?

Is the example the key part of that or does it also need an explanation that the docker plugin creates new agents based on labels requested by jobs? Those jobs can be Pipeline, freestyle, or matrix jobs.

from docker-plugin.

WilliamShoww avatar WilliamShoww commented on September 13, 2024

感谢您的报告@WilliamShoww

我不确定如何最好地描述插件与 Pipeline 的配合使用,因为它不是特定于 Pipeline 的。下面是我用来测试插件的示例。

以下管道作业使用在我的控制器上定义的带有‘alpine’标签的代理。

pipeline {
    agent {
        label 'alpine'
    }
    stages {
        stage('Hello from Alpine docker agent') {
            steps {
                sh 'whoami && uname -a && cat /etc/os-release && java -version && git --version'
            }
        }
    }
}

我的控制器上所有带有标签“alpine”的代理在请求时由docker插件启动,然后在作业完成时由docker插件停止。当我运行该作业时,控制台输出报告:

Started by user Mark Waite
[Pipeline] Start of Pipeline
[Pipeline] node
Running on alpine-jdk21-00048adis7zag on mark-pc2 in /home/jenkins/agent/workspace/alpine-whoami
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Hello from Alpine docker agent)
[Pipeline] sh
+ whoami
jenkins
+ uname -a
Linux abf179eeac7d 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May  7 09:00:52 UTC 2 x86_64 Linux
+ cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.19.1
PRETTY_NAME="Alpine Linux v3.19"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
+ java -version
openjdk version "21.0.3" 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode)
+ git --version
git version 2.43.0
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[Gitea] do not publish assets due to source being no GiteaSCMSource
Finished: SUCCESS

在我的 Jenkins 控制器的配置即代码定义中,我有以下条目:

jenkins:
  clouds:
  - docker:
      containerCap: 3
      dockerApi:
        connectTimeout: 23
        dockerHost:
          uri: "tcp://docker-host.markwaite.net:2375"
        readTimeout: 43
      errorDuration: 313
      name: "mark-pc2"
      templates:
      - connector:
          jnlp:
            jenkinsUrl: "http://mark-pc2.markwaite.net}:8080/"
            user: "1000"
        dockerTemplateBase:
          cpuPeriod: 0
          cpuQuota: 0
          image: "jenkins/inbound-agent:3248.v65ecb_254c298-2-alpine-jdk21"
        labelString: "alpine jdk21 alpine-jdk21 git-2.43"
        name: "alpine-jdk21"
        pullTimeout: 171
        remoteFs: "/home/jenkins/agent"

该配置作为代码条目描述了“高山”标签的代理定义。

这有助于回答你的问题吗?

这个例子是关键部分吗?还是还需要解释一下 Docker 插件根据作业请求的标签创建新代理?这些作业可以是管道作业、自由式作业或矩阵作业。

Thanks for the report @WilliamShoww .

I'm not sure of the best way to describe using the plugin with Pipeline, since it is not specific to Pipeline. Here is an example that I use to test the plugin.

The following Pipeline job uses an agent with the 'alpine' label defined on my controller.

pipeline {
    agent {
        label 'alpine'
    }
    stages {
        stage('Hello from Alpine docker agent') {
            steps {
                sh 'whoami && uname -a && cat /etc/os-release && java -version && git --version'
            }
        }
    }
}

All agents with the label 'alpine' on my controller are started by the docker plugin when requested, then stopped by the docker plugin when the job completes. When I ran that job, the console output reported:

Started by user Mark Waite
[Pipeline] Start of Pipeline
[Pipeline] node
Running on alpine-jdk21-00048adis7zag on mark-pc2 in /home/jenkins/agent/workspace/alpine-whoami
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Hello from Alpine docker agent)
[Pipeline] sh
+ whoami
jenkins
+ uname -a
Linux abf179eeac7d 6.5.0-35-generic #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May  7 09:00:52 UTC 2 x86_64 Linux
+ cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.19.1
PRETTY_NAME="Alpine Linux v3.19"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
+ java -version
openjdk version "21.0.3" 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode)
+ git --version
git version 2.43.0
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[Gitea] do not publish assets due to source being no GiteaSCMSource
Finished: SUCCESS

In the configuration as code definition for my Jenkins controller, I have the following entry:

jenkins:
  clouds:
  - docker:
      containerCap: 3
      dockerApi:
        connectTimeout: 23
        dockerHost:
          uri: "tcp://docker-host.markwaite.net:2375"
        readTimeout: 43
      errorDuration: 313
      name: "mark-pc2"
      templates:
      - connector:
          jnlp:
            jenkinsUrl: "http://mark-pc2.markwaite.net}:8080/"
            user: "1000"
        dockerTemplateBase:
          cpuPeriod: 0
          cpuQuota: 0
          image: "jenkins/inbound-agent:3248.v65ecb_254c298-2-alpine-jdk21"
        labelString: "alpine jdk21 alpine-jdk21 git-2.43"
        name: "alpine-jdk21"
        pullTimeout: 171
        remoteFs: "/home/jenkins/agent"

That configuration as code entry describes the agent definition for the 'alpine' label.

Does that help answer your question?

Is the example the key part of that or does it also need an explanation that the docker plugin creates new agents based on labels requested by jobs? Those jobs can be Pipeline, freestyle, or matrix jobs.

I didn't understand what you meant. It seems like the method you mentioned didn't solve my problem. After looking at the source code, what I want is a way to describe the exact same functionality as the src/main/java/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher.java class using a scripting language in the pipeline. Because I want to use this plugin with a script in the matching line, similar to the configuration in a freestyle project, in Jenkins without having Docker software installed.
freestyle project use way see img:
image

from docker-plugin.

MarkEWaite avatar MarkEWaite commented on September 13, 2024

what I want is a way to describe the exact same functionality as the src/main/java/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher.java class using a scripting language in the pipeline

I don't intend to add that type of capability to the plugin. The Pipeline already has facilities that allow a Jenkins provided credential to be provided to shell steps that can perform command line operations like docker push. I recommend that you use those facilities rather than waiting for an implementation inside the Jenkins docker plugin.

from docker-plugin.

WilliamShoww avatar WilliamShoww commented on September 13, 2024

what I want is a way to describe the exact same functionality as the src/main/java/com/nirima/jenkins/plugins/docker/builder/DockerBuilderPublisher.java class using a scripting language in the pipeline

I don't intend to add that type of capability to the plugin. The Pipeline already has facilities that allow a Jenkins provided credential to be provided to shell steps that can perform command line operations like docker push. I recommend that you use those facilities rather than waiting for an implementation inside the Jenkins docker plugin.

If I use native commands, docker must be installed on my jenkins machine, otherwise the docker command cannot be executed.
My situation is: Jenkins is started through the docker image, then I need to install another docker in the image container or need to share the socket file directory mapping docker when starting. If such a method is provided, then I don’t have to do these things.

from docker-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.