ngrok demo

怎么用

https://dashboard.ngrok.com/get-started
ngrok_demo_01

1
2
➜  Downloads ./ngrok authtoken <YOUR_AUTHTOKEN>
Authtoken saved to configuration file: /Users/xxx/.ngrok2/ngrok.yml

Demo on jenkins

  1. 启动本地的Jenkins服务,暴露端口 8081
1
2
3
4
5
➜  jenkins_demo docker run -d --name jenkins4ngrok -p 8081:8080 jenkins/jenkins:latest
c384aca32c27d2c2df58e76619bc63a758d5e7b358e59c5bf083cb739952c4c7
➜ jenkins_demo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c384aca32c27 jenkins/jenkins:latest "/sbin/tini -- /usr/…" 2 seconds ago Up 1 second 50000/tcp, 0.0.0.0:8081->8080/tcp jenkins4ngrok
  1. Use ngrok, To start a HTTP tunnel on port 8081
    ➜ ./ngrok http 8081

ngrok_demo_03

  1. 根据ngrok返回的,访问公网地址

界面如下
ngrok_demo_02

More Ref:

Makefile 105: syntax

5.1 注释

井号(#)在Makefile中表示注释。

1
2
3
4
# 这是注释
result.txt: source.txt
# 这是注释
cp source.txt result.txt # 这也是注释
5.2 回声(echoing)

@ suppress the normal ‘echo’ of the command that is executed.
正常情况下,make会打印每条命令,然后再执行,这就叫做回声(echoing)。

1
2
3
test:
# 这是测试
执行上面的规则,会得到下面的结果。
1
2
$ make test
# 这是测试

在命令的前面加上@,就可以关闭回声。

1
2
test:
@# 这是测试

5.3 减号-

- means ignore the exit status of the command that is executed (normally, a non-zero exit status would stop that part of htat build)

通常情况下,Makefile在执行到某一条命令时,如果返回值不正常,就会推出当前make进程,通常结合 rm ,mkdir 命令使用,(空文件或者文件不存在都会返回错误)

这个符号的目的就是如果这条命令执行失败了继续执行,不影响后续命令的执行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
➜   cat Makefile
all: stage1 stage2

stage1: ;@echo "run stage1.....";
@echo "I am stage1"

stage2:
echo "I am stage2"

#执行
➜ make
run stage1.....
I am stage1
echo "I am stage2"
I am stage2

5.4 加号+

+ means execute this comand under make -n (when commands are not normally executed)
对于命令行前面加上加号+的含义,表明在使用 make -n 命令的时候,其他行都只是显示命令而不执行,只有+ 行的才会被执行。

Makefile 104: Help

help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
➜  example_stages cat Makefile
.DEFAULT_GOAL := help


help: ## show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'


stage1: ## This message will show up when typing 'make help'
@echo I am stage1

stage2:
echo "I am stage2"
➜ example_stages make help
help: show this help
stage1: This message will show up when typing 'make help'

output:

1
2
3
➜   make help
help: show this help
stage1: This message will show up when typing 'make help'

Makefile 103: all & clean

makefile 中的all

因为 makefile 的执行流程是找到第一个目标作为最终生成的目标,如果顺序错乱了,makefile 就可能报错,all 方法就是解决这个问题而存在的,并且,all 方法可以让一个 makefile 生成多个目标。示例如下:

makefile 中的 clean

make clean 命令是用来清除目录下临时文件的,执行 clean 这个目标时,不需要任何依赖项,也就意味着,如果目录下有一个文件名为 clean 的话,执行 make clean 命令时会判断这个目标所依赖的内容是否有变化,如有变化则重新生成,无变化则跳过,而恰恰我们这个 clean 没写依赖规则!这将导致 clean 无论如何都不会被执行。解决这个问题的办法就是将 clean 方法声明为一个伪目标,做就就是让 clean 无论如何都更新,同样我们生成的 all 目标也可能会出现这种情况,所以我们将它们两个都声明为 伪目标,方法如下:

1
2
3
4
clean:
-rm -rf $(obj) main app

.PHONY:clean all

Makefile 102:Variable

Variables (common use)
1
2
3
4
origin_file = hello.c

hellofrommakefile: $(origin_file)
gcc hello.c -o hellofrommakefile
1
2
3
4
5
env := "local"

task1:
@echo "hello ,task1"
@echo "This is environment: $(env)

设置变量 env,如果在执行make时不传值,则使用默认值 local, 输出如下:

1
2
3
4
5
6
7
8
9
# 不给env值
make
hello ,task1
This is env: local

# 给env=uat
make env=uat
hello ,task1
This is env: uat
Automatic Variables(自动变量)

makefile 中有一些预定义的变量,你可以理解它像是 C 语言中的一些关键字,分别有不同的意义,我们列举几个常用的自动变量,其他还有很多

$@:在命令中使用,表示规则中的目标
$<:在命令中使用,表示规则中的第一个条件
$^:在命令中使用,表示规则中的所有条件,组成一个列表,以空格隔开,如果这个列表中有重复的项则消除重复项。

1
2
hellofrommakefile: hello.c
gcc hello.c -o hellofrommakefile

等价于

1
2
hellofrommakefile: hello.c
gcc hello.c -o $@

mplicit Variables(内置变量)

Make命令提供一系列内置变量,比如,$(CC) 指向当前使用的编译器,$(MAKE) 指向当前使用的Make工具。这主要是为了跨平台的兼容性,详细的内置变量清单见ta

More Ref:

Makefile 101 :Intro

新建文件 ,文件名 makefile 或 Makefile

格式:
target: dependencies

command

目标:要生成的目标文件
依赖:目标文件由哪些文件生成
命令:通过执行该命令由依赖文件生成目标

工作原理:

1、若想生成目标,检查规则中的依赖条件是否存在,如不存在,则寻找是否有规则用来生成该依赖文件

2、检查规则中的目标是否需要更新,必须先检查它的所有依赖,依赖中有任一个被更新,则目标必须更新

分析各个目标和依赖之间的关系
根据依赖关系自底向上执行命令
根据修改时间比目标新,确定更新
如果目标不依赖任何条件,则执行对应命令,以示更新

Example 1:

gcc test.c -o test // 根据test.c文件,编译一个 test的可执行文件出来

➡ 用makefile来完成这一过程如下:

1
2
test: test.c
gcc test.c -o test

执行:

1
2
➜   make
gcc hello.c -o hellofrommakefile

Example 2:
1
2
3
4
5
6
7
8
9

main: main.c tool.o
gcc main.c tool.o -o main

tool.o: tool.c
gcc -c tool.c

clean:
rm *.o main

执行命令 make

执行 make clean

Example 3:

执行所有的target

1
2
3
4
5
6
7
8

all: stage1 stage2

stage1:
@echo "I am stage1"

stage2:
echo "I am stage2"

output:

1
2
3
4
➜  example_stages make
I am stage1
echo "I am stage2"
I am stage2

Example 4:
other FAQs:
  • 编译的时候一直报makefile:29: *** missing separator错误。最后定位到是语法错了。输入的tab键被编辑器自动替换成4个空格了,导致一直报错;vim下可以这样写入tab键:ctr+v+i,会写入一个tab键
  • 对每个 .c 文件进行编译,生成 .o 文件,然后对几个 .o 文件联合编译生成可执行的文件

More Ref:

Jenkins Unicode icons

Unicode icons list:

“\u2776” = ❶
“\u27A1” = ➡
“\u2756” = ❖
“\u273F” = ✿
“\u2795” = ➕

“\u2713” = ✓
“\u2705” = ✅
“\u274E” = ❎
“\u2717” = ✗
“\u274C” = ❌

“\u2600” = ☀
“\u2601” = ☁
“\u2622” = ☢
“\u2623” = ☣
“\u2639” = ☹
“\u263A” = ☺

Example :
make stage name to a icon, or command message

1
2
3
4
5
6
7
8
9
10
11
12
//declarative pipeline
...
stages {
stage('\u270A RAISED FIST'){
steps{
script{
echo "This is Stage One"
currentBuild.displayName = "${env.BUILD_NUMBER} -> ${env.GIT_BRANCH}"
}
}
}
...

1
2
echo '\u273F Verify' //u2700
echo '\u2620 kulou' //u2600

More Ref:

Jenkins add timestamps

Timestamper plugin: Adds timestamps to the Console Output

Method One: use options

1
2
3
4
5
6
7
//declarative pipeline
pipeline {
agent any
options {
timestamps ()
}
}

Example output:

1
2
3
4
5
6
7
16:21:40 + echo 23
16:21:40 23
[Pipeline] sh
16:21:41 + echo master , test.BuiltInFunction/Devops_Tools/demo-from-git
16:21:41 master , test.BuiltInFunction/Devops_Tools/demo-from-git
[Pipeline] echo
16:21:41 haha

Method Two: use wrap

//declarative pipeline
pipeline {
    agent any   
    stages {
        stage('Stage with timestamp'){
            steps{
                sh "echo ${env.BUILD_NUMBER}"
                wrap([$class: 'TimestamperBuildWrapper']) {
                  echo "Done"
                }
            }
        }
    }    
}

默认是到分钟级别,到秒级别的需要自己定义格式,或者在菜单左侧,选择“Elapsed time”

More Ref:

  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~