0

如何使用 Jenkins/Maven 插件生成模式名称以测试我的应用程序。我需要这个模式名称是唯一的(在 DB - Oracle/SQL 中不存在)。是否有 Jenkins 独特的字符串生成器?

4

1 回答 1

2

If you are using the Execute Shell command, then the BUILD_ID and BUILD_NUMBER are available to you along with the BUILD_TAG. The BUILD_TAG is going to be completely unique amongst Jenkins builds (it's jenkins-${JOB_NAME}-${BUILD_NUMBER}), but may be too long or depending on your job name, may contain characters that are inappropriate for your database.

However, these variables can be used to construct unique, but identifiable names which you can use later for things like looking at the database output from a particular run or cleaning up all database that were before a certain job.

If you're not using Execute Shell, then the Inject environment variables to the build process option will put these same variable directly into the build environment, where they can be accessed by your code (assuming you can access environment variables).

Database naming

For Oracle, it appears that database names are still limited to 8 characters (as of the last reference that I found) and so you'll likely need to use a short static string with the BUILD_NUMBER appended to it, which is pretty simple to create in the shell.

If you're worried about the BUILD_NUMBER becoming too large, then you can always reduce the space by doing something like encoding it in hex (reducing the characters used for the same number and still using characters guaranteed to be valid in ASCII).

If that's insufficient, I've used base64 encoding for values that I needed to be stored in ASCII, but were too large for the storage space. If, for example, you take 3 binary bytes and encode to base64, you'll get 4 ASCII bytes, which you could use as half of the database name. The range there is roughly 24 million builds, which should be sufficient, and the decoding is simple. Of course, you'll have to convert the number to binary first in order to do the encoding (base64 of the ASCII version of the number would serve no purpose).

于 2013-05-09T10:28:26.410 回答