Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yml 全局变量? #34

Open
sdaduanbilei opened this issue Apr 13, 2018 · 9 comments
Open

yml 全局变量? #34

sdaduanbilei opened this issue Apr 13, 2018 · 9 comments

Comments

@sdaduanbilei
Copy link

flow:
  - envs:
        FLOW_AGENT_WORKSPACE: ${HOME}/agent-workspace
        FLOW_ENV_OUTPUT_PREFIX: ANDORID_OUTPUT_
        ANDROID_GRADLE_BUILD_TASK: assembleRelease
        ANDROID_PROJECT_NAME: youprojectname
    steps:
      - name: Git Clone #rm -r -f 每次都会删除项目,重新clone
        script: | 
            rm -r -f ${ANDROID_PROJECT_NAME} 
            export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
            git clone --branch ${FLOW_GIT_BRANCH} --single-branch ${FLOW_GIT_URL} ${ANDROID_PROJECT_NAME}
            cd ${ANDROID_PROJECT_NAME}
            lastlog=`git log -1`
            export GIT_COMMIT_LOG=${lastlog}
            echo current git log${GIT_COMMIT_LOG}
      - name: QQBOT ## qq 机器人发送通知消息
        script: |
            echo ${GIT_COMMIT_LOG}

我想实现的功能是 在 git clone 的时候读取 commit 记录,然后给 GIT_COMMIT_LOG , 中间构建步骤忽略, 我在最后一步 通过qq 机器人 发送 消息到群里 内容就是GIT_COMMIT_LOG 这样的写法未成功,我看到 你们提供的 android.flow.ymlANDROID_OUTPUT_IPA_PATH 有类似的使用, 我尝试模仿着写 但是未成功 echo current git log:${GIT_COMMIT_LOG} 这里已经打印出来commit信息

@sdaduanbilei sdaduanbilei changed the title yml 模板 yml 全局变量? Apr 13, 2018
@yunheli
Copy link
Contributor

yunheli commented Apr 13, 2018

@sdaduanbilei 把变量 GIT_COMMIT_LOG 改为 ANDORID_OUTPUT_GIT_COMMIT_LOG

@yunheli
Copy link
Contributor

yunheli commented Apr 13, 2018

这个配置FLOW_ENV_OUTPUT_PREFIX: ANDORID_OUTPUT_ 意思是只共享前缀是 ANDROID_OUTPUT_的环境变量

@sdaduanbilei
Copy link
Author

@yunheli 成功了
但是为什么得这样写?
还有第一步是不是可以实现,检测到commit 和上一次不相同了 我在 进行全部流程的编译 上传, 如果相同 我就直接结束, Webhook 由于是台物理机只能局域网使用,我现在是 定时检测

@yunheli
Copy link
Contributor

yunheli commented Apr 13, 2018

@sdaduanbilei
第一个问题:环境变量太多,所以只能存一些指定的环境变量,因为这些环境变量要入库
第二个问题:你把上次最新的commit写到一个文件,下次编译的时候读一下文件的上次保存的commit 不同的话就继续

@yunheli
Copy link
Contributor

yunheli commented Apr 13, 2018

至于环境变量的前缀是什么可以自己定义

@sdaduanbilei
Copy link
Author

@yunheli 如何结束 停止不进行往下走呢? exit 好像不管用!

@sdaduanbilei
Copy link
Author

sdaduanbilei commented Apr 13, 2018

@yunheli

flow:
  - envs:
        FLOW_AGENT_WORKSPACE: ${HOME}/agent-workspace
        FLOW_ENV_OUTPUT_PREFIX: ANDORID_OUTPUT_
        ANDROID_GRADLE_BUILD_TASK: assembleRelease
        ANDROID_PROJECT_NAME: youprojectname
    steps:
      - name: Git Clone #rm -r -f 每次都会删除项目,重新clone
        script: |
          rm -r -f ${ANDROID_PROJECT_NAME} 
          export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
          git clone --branch ${FLOW_GIT_BRANCH} --single-branch ${FLOW_GIT_URL} ${ANDROID_PROJECT_NAME}
          cd ${ANDROID_PROJECT_NAME}
          export GIT_COMMIT_ID=`git rev-parse HEAD` # 获取最后一个 commit id
          export ANDORID_OUTPUT_GIT_COMMIT_LOG=`git log -1`
          COMMIT_PAHT=${HOME}/${ANDROID_PROJECT_NAME}.txt
          echo current git log:${ANDORID_OUTPUT_GIT_COMMIT_LOG}

          if [ -f "${COMMIT_PAHT}" ] # 判断文件是否存在
            then
              cat ${COMMIT_PAHT} | while read LINE # 读取本地的commit id
              do 
                if [[ ${LINE} == ${GIT_COMMIT_ID} ]]
                  then
                    rm -r -f ${ANDROID_PROJECT_NAME}
                    echo Everything up-to-date
                    [["]]
                    exit
                  else
                    echo ${GIT_COMMIT_ID} > ${COMMIT_PAHT} # 以项目名,保存commit id到本地
                fi
              done
            else
              echo ${GIT_COMMIT_ID} > ${COMMIT_PAHT} # 以项目名,保存commit id到本地
          fi
      - name: QQBOT ## qq 机器人发送通知消息
        script: |
            echo ${ANDORID_OUTPUT_GIT_COMMIT_LOG}

已经实现commit 版本对比,成功输入 Everything up-to-date 但是执行 exit 后 还是会继续下面的 step 要如何停止呢

在线急等

@sdaduanbilei
Copy link
Author

sdaduanbilei commented Apr 13, 2018

@yunheli

Everything up-to-date
/bin/bash:行19: [[]]: 未找到命令

我目前在 这里写上一个 错误的命令,然后让整个过程出错!
issues 我先开着

@yunheli
Copy link
Contributor

yunheli commented Apr 18, 2018

@sdaduanbilei 可以看文档 有 condition 条件比较

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants