写给那些想使用 JFrog Artifactory 管理制品的人

我在使用 Artifactory 做持续集成已经有一段时间了,对企业级 Artifactory 也有了一些经验和总结,希望能通过本篇的分享帮助刚接触这个工具的人了解什么是Artifactory,它能做什么,为什么要选择它,以及在使用过程中应该注意什么。

什么是Artifactory

一句话概括:Artifactory 是一个存放制品(Artifacts)的工具。当前,Artifactory 是一个非常有影响力,功能非常强大的工具。

Artifactory有哪些优势

可能你的团队已经有了自己的管理制品的方式,比如 FTP 等。Artifactory 能带来什么呢?让我先来看看它有哪些优势。

注:以下优势都是针对 JFrog Aritifacvtory 企业版来介绍的。开源版,即 OSS 版本不具备以下丰富的功能。

优势1:它是一个通用管理仓库

JFrog Artifactory 企业版完全支持所有主要包格式的存储库管理器。它不但可以管理二进制文件,也可以对市面上几乎所有语言的包的依赖进行管理,如下图所示

主要的包格式

因此,使用 Artifactory 能够将所有的二进制文件和包存储在一个地方

Read More

程序员自我修养之Git提交信息和分支创建规范

为什么要制定规范

古话说,没有规矩不成方圆。在团队协作开发时,每个人提交代码时都会写 commit message,但如果没有规范,每个人都会有自己的书写风格,因此在翻看 git log 时经常看到的是五花八门,十分不利于阅读和维护。

通过下面两个例子来看看没规范和有规范的对比,以及有规范能带来哪些好处。

提交信息 没规范 vs 有规范

没有规范的 Git 提交信息

从这个提交信息里你不知道他修改了什么,修改意图是什么。

Read More

在 GitHub 上发布一个 Python 项目需要注意哪些

本篇介绍个人或企业在 GitHub 上发布一个 Python 项目需要了解和注意哪些内容

  1. 如何配置setup.py
  2. 如何发布到PyPI
  3. 生成pydoc
  4. 版本号的选择
  5. License的选择

配置setup.py

打包和发布一项都是通过准备一个 setup.py 文件来完成的。假设你的项目目录结构如下:

demo
├── LICENSE
├── README.md
├── MANIFEST.in # 打包时,用来定制化生成 `dist/*.tar.gz` 里的内容
├── demo
│ └── __init__.py
├── setup.py
├── tests
│ └── __init__.py
│ └── __pycache__/
└── docs

在使用打包命令 python setup.py sdist bdist_wheel,将会生成在 dist 目录下生成两个文件 demo-1.0.0-py3-none-any.whldemo-1.0.0.tar.gz

  • .whl 文件是用于执行 pip install dist/demo-1.0.0-py3-none-any.whl 将其安装到 ...\Python38\Lib\site-packages\demo 目录时使用的文件。

  • .tar.gz 是打包后的源代码的存档文件。而 MANIFEST.in 则是用来控制这个文件里到底要有哪些内容。

Read More

About Python pip install and versioning

Backgroup

If you want to release python project on PyPI, you must need to know about PyPI usage characteristics, then I did some test about pip install command.

For example: I have a Python project called demo-pip. and beta release would like 1.1.0.xxxx, offical release version is 1.1.0 to see if could success upgrade when using pip command.

Base on the below test results, I summarized as follows:

  1. Install a specific version of demo-pip from PyPI, with --upgrade option or not, they’ll all both success.
  2. Install the latest package version of demo-pip from PyPI that version is large than the locally installed package version, with --upgrade option installs successfully. without --upgrade option install failed.
  3. Install the latest package version of demo-pip from PyPI that version is less than the locally installed package version, with --upgrade option or not, install failed.
  4. 1.1.0.xxxx version naming is OK, but when the beta version is larger than 1.1.0, for example, the beta version is 1.1.0.1000, pip install with --upgrade not work when our official release version is 1.1.0.
    a. One option is the official release version start from 1.1.0.1000, beta version starts from 1.1.0.0001, 1.1.0.0002… Or the beta version should be less than 1.1.0, maybe 1.0.0.xxxx
    b. Another option is follow up python official versioning that is the best practice, then the beta release version will be 1.1.b1, 1.1.b2, 1.1.bN… (it passed No.5 test below)

My Test Case

Read More

Update Jira server account avatar with rest API

Backgroud

When you are using a server account for CI/CD, if you want to make the server account avatar to looks professional on Jira update but the server account may not allowed to log to Jira, so you can not update the avatar though GUI, you could use Jira REST API to do this.

I assume you have an account called robot, here are the examples of how to update though REST API.

Example in Python

import http.client

conn = http.client.HTTPSConnection("jira.your-company.com")

payload = "{\r\n\t\"id\": \"24880\",\r\n\t\"isSelected\": false,\r\n\t\"isSystemAvatar\": true,\r\n\t\"urls\": {\r\n\t\t\"16x16\": \"https://jira.your-company.com/secure/useravatar?size=xsmall&avatarId=24880\",\r\n\t\t\"24x24\": \"https://jira.your-company.com/secure/useravatar?size=small&avatarId=24880\",\r\n\t\t\"32x32\": \"https://jira.your-company.com/secure/useravatar?size=medium&avatarId=24880\",\r\n\t\t\"48x48\": \"https://jira.your-company.com/secure/useravatar?avatarId=24880\"}\r\n}"

headers = {
'content-type': "application/json",
'authorization': "Basic Ymx3bXY6SzhNcnk5ZGI=",
'cache-control': "no-cache",
'postman-token': "ecfc3260-9c9f-e80c-e3e8-d413f48dfbf4"
}

conn.request("PUT", "/rest/api/latest/user/avatar?username=robot", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

Example in Postman

Read More

Fixed "Remote session was disconnected because there are no Remote Desktop client access licenses available"

Problem

Sometimes my Windows server 2012 R2 has RDP connect problem below:

The remote session was disconnected because there are no Remote Desktop client access licenses available for this computer.
Please contact the server administrator.

RDP connect problem

Read More

通过 generic-webhook-trigger 插件实时获取 Bitbucket Repository Events

背景

本篇讨论如何通过 Jenkins generic webhook trigger 插件来获取 Git 仓库事件(Events)。比如获取仓库的 Pull Request ID 等。

使用过 Jenkins Multi-branch pipeline Job 的用户知道,这个 Job 类型的环境变量中可以得到 Pull Request 的相关信息如下

Multi-branch pipeline Job 环境变量

为了获取这个变量需要创建这种类型的 Job,并且可能需要 clone 该仓库的代码,有点杀鸡宰牛的意思,看起来并不是一个特别恰当的办法。

如何通过创建一个普通的 Jenkins Job 就能实时获取 Bitbucket 仓库以及 Pull Request 事件呢?通过以下功能和插件可以实现。

Read More

Annual work summary from 2019.03 - 2020.07

Summarize what did I do from 2019.03 to 2020.07 when I became a Build Release/DevOps engineer.

Build automation

  • Support all server windows platform build manual to auto.
  • Support clients build from manual to auto.
  • Switch Linux/Unix build from Bamboo to Jenkins.
  • Support all platforms branches/Pull Request build.
  • Provide auto-build as self-service for a developer, no need to involve build engineer, they could build themselves.

Integration

  • Integration with Jenkins

    • Self-service installation.
    • Blackduck, Polaris integration.
    • Git stats, analyze Bitbucket data with Elastic stack.
    • Monitor legacy build machines status.
    • Product escrow, sync xdemo, provide NFS and SYNC mvopensrc, update Bitbucket Jenkins build status, etc.
  • Integration with JFrog Ariifactory

    • Establish deploy strategy and directory structure organization.
    • Handle artifacts(build, etc) with different maturity.

Infrastructure management

  • Manage Jenkins for setting, update and backup.
  • Ariifactory artifacts cleanup, retention, backup.
  • Git branches/hooks management.
  • VMs tracking, management build machines.

Jenkins 执行 Shell 如果返回值不为0,作业(Job)停止并失败怎么办?

《Jenkins Tips 3》—— 每期用简短的图文描述一个 Jenkins 小技巧。

问题

在使用 Jenkins pipeline 时,如果 Shell 的返回值不为零(也就是 Shell 命令执行时有错误),Jenkins Job 默认会标记当前的 stage 为失败。因此整个 Job 也会失败。

在有些时候我们希望 Shell 虽然执行失败返回的不为零,但希望Jenkins Job 在执行成功后,要显示成功状态。

Read More

How to fix ".NET Framework 2.0 or later is required on this computer to run a Jenkins agent as a Windows service"

When I upgrade Jenkins 2.176.3 to Jenkins 2.235.1, my Windows agent can not connect with master successfully and outcome this warning message “.NET Framework 2.0 or later is required on this computer to run a Jenkins agent as a Windows service”.

Read More