Thursday, June 29, 2023

Jnkins build to distbute

利用上下游的機制,讓管家先生一口氣編好測試&正式環境的 apk 後,除了各自上傳到 ftp 外,再透過 API 送到 play store alpha 



 



原本同事在一台 mbp 上建好一台 jenkins 包 iOS
但要透過遠端控制,覺得應該可以直連 jenkins web service 會更順暢
找了一下發現這邊可以這樣做:

We want the Jenkins web interface to be accessible from anywhere (not just on the local machine), 
so we’re going to open up the config file:
sudo nano /usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.plist

Find this line:

<string>--httpListenAddress=127.0.0.1</string>

And change it to:

<string>--httpListenAddress=0.0.0.0</string>


搞定 web service 後就來建 android project
原先有看到 pipeline,寫的 scipt 好像很自由,但還沒參透,先用 project 
之後再續戰 pipeline


設定好 git repo & Execute shell (就是 gradlew 產 apk 那條)
試跑出來成功啦~



但是... apk 咧XD
加上這個

add Build Artifacts feature




就跑出載點啦



其實它在 Workspace 下,就跟 IDE 裡面左邊的 project 那樣點一點就看得到
不過可以有傳送門總是比較方便,你說是吧XD




可以加裝 plugin 使用 Gradle Wrapper, 但下指令可以有更多彈性~




目前的需求是要組出上傳到 ftp server 的 apk link, 透過原本的 gradle 在組擋名的時候
順便組 link 印出來在 console log 上方便複製(懶惰萬歲XD)
(更懶可以再接上 slack)

那接下來就要開放選擇口味,要搭配 Jenkins 的變數傳入 build script

參數列表網址:http://your.domain.here:8080/env-vars.html/

先裝外掛

就可以開外掛啦~










跑之前先確認 commit id


挑好 branch 



挑好口味




跑的時候看 log 確實 check out 對應的 commit id




接下來要處理的是,把 version code 跟 build number 串在一起,不再以日期為準,而是跟著 build number 跑




同時在打包結束後,打好 tag 送上 repo 也是很便利的




BUILD SUCCESSFUL in 2m 56s
39 actionable tasks: 13 executed, 26 up-to-date
Build step 'Invoke Gradle script' changed build result to SUCCESS
Archiving artifacts
The recommended git tool is: NONE
using credential PullinSSHKey
 > git tag -l 1.2.3 # timeout=10
 > git tag -a -f -m 1.2.3 tag by build number 32 1.2.3 # timeout=10
ERROR: Failed to push tag 1.2.3 to origin
hudson.plugins.git.GitException: Could not apply tag 1.2.3
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.tag(CliGitAPIImpl.java:1849)
    ...skip...
    at java.base/java.lang.Thread.run(Thread.java:829)
    Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from localhost/127.0.0.1:49431
        at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784)
        at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
        ...skip...
        at hudson.model.ResourceController.execute(ResourceController.java:101)
        at hudson.model.Executor.run(Executor.java:442)
Caused by: hudson.plugins.git.GitException: Command "git tag -a -f -m 1.2.3 tag by build number 32 1.2.3" returned status code 128:
stdout: 
stderr: Committer identity unknown

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com" 
  git config --global user.name "Your Name" 

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <>) not allowed

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2671)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2601)
    ...skip...
    ... 17 more
Build step 'Git Publisher' marked build as failure
Finished: FAILURE

遇到 git ssh 憑證問題






整組呈現



擴充技能:build by git push

set change log parameter for Google Play



set credentials and apk path in Post-build action


set release track and rollout percentage


set 18n change log


10:31:31 Upload failed: 
10:31:31 - Google Play Android Developer API has not been used in project 544296638860 before or it is disabled. 
Enable it by visiting https://console.developers.google.com/apis/api/androidpublisher.googleapis.com/overview?project=544296638860 
then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
遇到 play api 問題,要先去啟用



還是噴錯

10:43:37 Upload failed: 10:43:37 - The project ID used to call the Google Play Developer API has not been linked in the Google Play Developer Console.
原來是接錯 gcp project ... = =a
按對後就成功啦~

11:47:59 Uploading 1 file(s) with application ID: dbx.******
11:47:59 
11:47:59          APK file: app/build/outputs/apk/pub/release/*****_20220914_vtest.ver.sion_pub_release.apk
11:47:59         File size: 61.34 MB
11:47:59        SHA-1 hash: 2ace634d7202b06671083dc7edd30fcfc08a489c
11:47:59       versionCode: 200701268
11:47:59       versionName: test.ver.sion
11:47:59     minSdkVersion: 21
11:48:26  
11:48:26 Updating release track 'internal':
11:48:26 - Application ID:  dbx.*****
11:48:26 - Version codes:   200701268
11:48:26 - Staged rollout:  0% (draft)
11:48:26 - Update priority: (default)
11:48:26 - Release name:    (default)
11:48:26 - Release notes:   en-GB, zh-TW
11:48:26 
11:48:26 Applying changes to Google Play...
11:48:30 Changes were successfully applied to Google Play

apk shown in App bundle explorer




as draft (0%) in internal release track



release name and release notes in edit release


18n for english release notes in review release


遇到問題

16:10:29 Failed to execute org.gradle.cache.internal.AsyncCacheAccessDecoratedCache$$Lambda$308/0x00000008004b6c40@7ca109ec.
16:10:29 org.gradle.api.UncheckedIOException: Could not add entry '/Users/jenkins/.gradle/caches/transforms-3/c1e8d385c310d60e608cd1b948ce68f4' to cache file-access.bin (/Users/jenkins/.gradle/caches/journal-1/file-access.bin).
16:10:29     at org.gradle.cache.internal.btree.BTreePersistentIndexedCache.put(BTreePersistentIndexedCache.java:162)
16:10:29     at org.gradle.cache.internal.DefaultMultiProcessSafePersistentIndexedCache.lambda$put$1(DefaultMultiProcessSafePersistentIndexedCache.java:67)
16:10:29     at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.doWriteAction(DefaultFileLockManager.java:216)
16:10:29     at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.writeFile(DefaultFileLockManager.java:206)
16:10:29     at org.gradle.cache.internal.DefaultCacheAccess$UnitOfWorkFileAccess.writeFile(DefaultCacheAccess.java:449)
16:10:29     at org.gradle.cache.internal.DefaultMultiProcessSafePersistentIndexedCache.put(DefaultMultiProcessSafePersistentIndexedCache.java:67)
16:10:29     at org.gradle.cache.internal.AsyncCacheAccessDecoratedCache.lambda$putLater$1(AsyncCacheAccessDecoratedCache.java:56)
16:10:29     at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
16:10:29     at org.gradle.cache.internal.CacheAccessWorker$2.run(CacheAccessWorker.java:185)
16:10:29     at org.gradle.internal.Factories$1.create(Factories.java:31)
16:10:29     at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:220)
16:10:29     at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:201)
16:10:29     at org.gradle.cache.internal.CacheAccessWorker.flushOperations(CacheAccessWorker.java:175)
16:10:29     at org.gradle.cache.internal.CacheAccessWorker.run(CacheAccessWorker.java:145)
16:10:29     at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
16:10:29     at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
16:10:29     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
16:10:29     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
16:10:29     at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
16:10:29     at java.base/java.lang.Thread.run(Thread.java:829)

清掉快取
rm -r $HOME/.gradle/caches/
java.nio.file.NoSuchFileException: /Users/jenkins/.gradle/caches/transforms-3

need to remove the whole .gradle folder to get it working
rm -rf ~/.gradle

遇到 oom

java.lang.OutOfMemoryError: Java heap space

同時跑兩個 job 引起的




加記憶體

JAVA_OPTS="-XX:MaxPermSize=2048M" 

但還是太吃力




JAVA_OPTS="-Xmx3072m" 
 13:42:26 The root cause java.lang.OutOfMemoryError was thrown at: unknown
13:42:26 Java heap space: KtProperty:

改成上下游的方式

上游 log

下游 log

可以順利跑完兩個啦(雖然不是同時XD)



除了 Jenkins 還有其他玩具可以試試看:

  • GitLab
  • TeamCity
  • fastlane
















Wednesday, June 28, 2023

Gitlab maitainance

 很久沒碰 linux,基本上還是現學現賣居多

靠著 s / l 大法慢慢 trial & error 


主要參考資訊

Pre-upgrade and post-upgrade checks

Upgrade paths

                

以前會提供像這樣個表格,讓你看某個版號要怎麼『按部就班』升級到最新版


現在變得比較簡單,用文字描述了



// incase it doesn't work after upgrade, just restart it 

sudo gitlab-ctl restart


// to the newest version

sudo yum install gitlab-ce


基本手順是:

sudo gitlab-rake gitlab:env:info // check version

// another way to check version : https://your.domain.here/api/v4/version

sudo gitlab-rake gitlab:check // upgrade status check

sudo gitlab-rake gitlab:doctor:secrets // upgrade status check

yum --showduplicates list gitlab-ce // list available updates
// 下列擇一

sudo yum install gitlab-ce // update to latest version if you've always up to date

sudo yum install gitlab-ce-15.9.4-ce.0.el7 // update speicific version

//非必要,遇到太久 500 可以使用

sudo gitlab-ctl restart 



如果遇到 web service 掛掉,也許可以參考這裡

我在這邊學到 sanitized gitlab.rb 

grep -v '^#\|^$' /etc/gitlab.rb


找到之前幫同事嘗試設定 gitlab page 時

參數設定錯了,先 mark 後升級就恢復正常XD


如果遇到系統明明亮紅燈,跟你說要盡快更新


(admin 登入,有緊急更新的話會一直鬼打牆提醒你XD)



如果直接走安裝最新更新,遇到更新檔有問題是,會吐 502 

然後列出更新檔案,看不到最新的版號




有可能是提供更新的服務壞掉了



                          




修好會寄信通知~



升級後遇到這兩個,通常等一兩分 or restart service 會好,

如果沒有... 就檢查 gitlab.rb 看哪邊怪怪的XD




升級成功的時候會有個小圖案,在 terminal 裡面看到這個很像過關動畫,很開心XD



如果失敗可以往回翻一下 log, error 會噴紅字,很貼心提供你指令直接修復XD



升級中搜集到的畫面,好可愛XD




升級完要健康檢查一下





有次遇到 cpu 超高


dbus-daemon high cpu usage

就算把 gitlab 停掉,還是很 high


找不到更新檔
改檢查更新

更新 dbus.x86_64

重開機後就乖了~